Validation macro

G

Guest

I am creating a macro to validate a user name and password for a login form.
I created a unbound form which has a text box for username and a text box for
password. The user will enter each text box and click on command button
"go". For the command button, I want to create a macro for the "on click"
event. The macro will validate the username and password entered into the
form against the username and password in the Users table. I am having
difficulty with the expression. I tried
[Forms]![frmLogin]![UserName]=[tblUsers]![UserName] And
[Forms]![frmLogin]![Password]=[tblUsers]![Password], but I receive a message
that "The object doesn't contain the Automation object "tblUsers."

Any advise will be appreciated
 
J

Jeff O via AccessMonster.com

Karen, Have the username be the primary key in the users table. then do the
following to vaidate.

Lets assume a couple things.
Your username textbox is called username
Your password textbox is called password

so:

in the on-click event for the "go" button:

Dim getuserrec As String
Dim getpass As Variant

getuserrec = "[Username] = " & "'" & username.value & "'"
getpass = DLookup("[password]", "users", getuserrec)

then some basic logic:

if getpass <> password.value then
msgbox "Your password doesn't match"
close the form or do something else
exit sub
else
allow them in
endif




I am creating a macro to validate a user name and password for a login form.
I created a unbound form which has a text box for username and a text box for
password. The user will enter each text box and click on command button
"go". For the command button, I want to create a macro for the "on click"
event. The macro will validate the username and password entered into the
form against the username and password in the Users table. I am having
difficulty with the expression. I tried
[Forms]![frmLogin]![UserName]=[tblUsers]![UserName] And
[Forms]![frmLogin]![Password]=[tblUsers]![Password], but I receive a message
that "The object doesn't contain the Automation object "tblUsers."

Any advise will be appreciated
 
S

Steve Schapel

Karen,

I assume you are referring to a Condition in your macro, right? Ok, try
like this...
[UserName]=DLookup("[UserName]","tblUsers") And
[Password]=DLookup("[Password]","tblUsers")

The syntax in the expressions you used are not really valid. Since the
macro is being run on the form that includes the textboxes, it is not
necessary to include the [Forms]!... blurb. And the structure
[tblUsers]![UserName] is something Access would not understand. Even if
it was a valid way of referring to a field in a table (which it's not),
Access would still need to be told which record in the table you want it
to relate to (even if the table only contains one record, doesn't alter
the fact).
 

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