VB Code Error

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.
 
A

Andrew Smith

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.
 
J

John Spencer (MVP)

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.
 

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