runtime error '2001'

  • Thread starter Thread starter michael goodall
  • Start date Start date
M

michael goodall

i am trying to run a piece of code that i know works to look up the
value of a query stored in a table, but when i try to run it, i get a
runtime error 2001 message. can anyone help me? the code i am using
is: If Nz(DLookup("admingroup", "group"), 0) = 2 Then DoCmd.OpenForm
"loginsuccessful" else msgbox "error". any assistance will be greatly
appreciated. michael
 
The following works for me:

Public Function fPickForm()
If Nz(DLookup("Index_Group", "A"), 0) = 2 Then
DoCmd.OpenForm "ASA"
Else: MsgBox "error"
End If
End Function

I noticed that you don't have an End If. Could that be the problem?

Have you compiled the code?

What happens when you run the following in the Immediate window?

Nz(DLookup("admingroup", "group"), 0)

Nz(DLookup("admingroup", "group"), 0) = 2
 
You can get this error if one of the names is wrong, e.g. if the field is
actually called [admin group] with a space.

Try adding square brackets around the table name as well, i.e. [group]
Group is a reserved word in JET SQL, so it might cause problems.
For a check list of words to avoid, see:
http://allenbrowne.com/AppIssueBadWord.html
 
Back
Top