VB Code Error

  • Thread starter Thread starter JObrien
  • Start date Start date
J

JObrien

This command

varX = DLookup("[password]","[Users]","[Username]
= "&Forms!session!UserID)

produces this error

The expression you entered in a query parameter produced
this error: "the object doesn't contain the automation
object 'Obrien'"

UserID was Obrien.

We're trying to simulate a password entry screen into a
change form and trying to validate password entry.

Any assistance is much appreciated.
 
You need to enclose the UserID in quotes as it is a string, otherwise it
will be interpreted as a variable name. The usual method is to use
apostrophes:

varX = DLookup("[password]","[Users]","[Username] = '"&
Forms!session!UserID & "'")

However you'll need something a bit cleverer than this if your usernames can
contain apostrophes or other special characters (eg if you might have a user
called O'Brien then this won't work). If your user names don't contain any
special characters then this method will work fine.
 
Try the following. It should work UNLESS Forms!Session!UserID contains a
quotation mark - apostrophes are not a problem.

VarX = DLookup("[password]","[Users]",
"[Username] = " & Chr(34) & Forms!session!UserID &Chr(34))

(All on one line)

Andrew said:
You need to enclose the UserID in quotes as it is a string, otherwise it
will be interpreted as a variable name. The usual method is to use
apostrophes:

varX = DLookup("[password]","[Users]","[Username] = '"&
Forms!session!UserID & "'")

However you'll need something a bit cleverer than this if your usernames can
contain apostrophes or other special characters (eg if you might have a user
called O'Brien then this won't work). If your user names don't contain any
special characters then this method will work fine.

This command

varX = DLookup("[password]","[Users]","[Username]
= "&Forms!session!UserID)

produces this error

The expression you entered in a query parameter produced
this error: "the object doesn't contain the automation
object 'Obrien'"

UserID was Obrien.

We're trying to simulate a password entry screen into a
change form and trying to validate password entry.

Any assistance is much appreciated.
 
Back
Top