The expression On Current...produced error.

  • Thread starter TraciAnn via AccessMonster.com
  • Start date
T

TraciAnn via AccessMonster.com

After opening my database and then opening a form I get the following error:

The expression On Current you entered as the event property setting produced
the following error:.
*The expression may not result in the name of a macro, the name of a user-
defined function, or [Event Procedure].
*There may have been an error evaluating the function, event, or macro.

This error occurs when an event has failed to run because Microsoft Office
Access cannot evaluate the location of the logic for the event. For example,
if the OnOpen property of a form is set to =[Field], this error occurs
because Access expects a macro or event name to run when the event is fired.

The error will continue if I attempt to use the combo box to select a record.
If I view code then return to the form, it functions as expected and the
error ceases. To cause it to occur again, all I need to do is close the
database and reopen.

Here is the On Current Event Procedure:

=========
Private Sub Form_Current()
Me.cboFindContact.Value = Me.ContactID
If Me.FilterOn Then
Me.cboFindContact.Enabled = False
Else
Me.cboFindContact.Enabled = True
End If
End Sub
=========

Thanks!
 
T

TraciAnn via AccessMonster.com

Bruce,

Thank you for your response.

I made sure Option Explicit was on from the beginning of the project, so it
didn't need added.

I did the Debug>>Compile and nothing came up. (I also did this prior to
posting). However, after closing and re-opening the app, it did not reoccur.
I know it wasn't a fluke thing because it has been going on for a week.

Also, thank you for the simplification of the code. All help is appreciated!

If you get the chance, I would like for you to look at my other post today
titled "Sub form chaos!!!", but it is much more envolved; so only if you have
the time.

Thanks!
Add this line at the top of the code window just below Option Compare
Database, if it is not there already:
Option Explicit

Now try compiling the code (Debug >> Compile). That error message does not
necessarily refer to code in the Current event, in spite of what it
suggests. My guess is that you will find something in the code that does
not compile.

If Option Explicit is not there, in the VBA editor click Tools >> Options.
On the Editor tab check Require Variable Declaration

This will add that line to future VBA modules.

I can see nothing in your code that jumps out at me as a problem, but you
could simplify a little:

Me.cboFindContact = Me.ContactID
Me.cboFindContact.Enabled = Not Me.FilterOn

FilterOn is Boolean (Yes/No), as is the Enabled property. Often it is
possible to use a Yes/No (True/False) expression to set another True/False
property without having to go through an If - Then statement.
After opening my database and then opening a form I get the following
error:
[quoted text clipped - 33 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top