[AccessD] The expression you entered refers to an object that is closed or doesnt exist.

jwcolby jwcolby at colbyconsulting.com
Fri Jan 25 02:59:25 CST 2008


How many of you have come across that error?

I have a system where the user selects some criteria, then a form is opened
using that criteria.  There is a command button that is the "default" button
(clicked if the user hits enter) which loads the form, so the user can
either click the button with the mouse or just hit enter.

I was getting "The expression you entered refers to an object that is closed
or doesn't exist." very occasionally as the form opened.  I finally
discovered that if I tapped the enter key several times as the form loaded,
Access sensed TWO key clicks and thus tried to open the form a second time.
I got rid of the error with the following code:

Private Sub but_wrksht_Click()
On Error GoTo Err_but_wrksht_Click
Static blnOpening As Boolean
    If blnOpening Then Exit Sub
    blnOpening = True
    OpenClaimFrm
    blnOpening = False
Exit_but_wrksht_Click:
Exit Sub
end sub

As you can see, I create a static variable, set it to True as I pass through
the first time and clear it again as the OpenClaimForm() finished.  If the
click event is sensed a second time while the OpenClaimForm() is still
processing, the blnOpening is still true and the sub is exited.

What a PITA Access is sometimes.

John W. Colby
Colby Consulting
www.ColbyConsulting.com 




More information about the AccessD mailing list