"If" condition on button action

sstasiak

Registered User.
Local time
Today, 02:12
Joined
Feb 8, 2007
Messages
97
I have a table, tblEmp, which holds fields [USERNAME], and [PASSWORD].

I also have a form, frmAuthenticate, with 2 unbound text boxes...one for the username and one for password. What I want to happen is that when I input a username and associated password, the name entered will be matched up to a [USERNAME] in tblEmp, then once a match is found it will also verify that what was entered in the text box, matches what's in the record. Once the two fields are verified to be equal, another form should open.

I don't know VBA well, but an idea of what the pseudo-code behind the "OnClick" action would be:

If [Text in username field in frmAuthenticate = a username in tblEmp]

And

If [Text in password field in frmAuthenticate = password for username specified above]

Then [Open frmOncRegMain]

This is how it should work, but I have no idea of how to properly code that. Any help is appreciated.
 
You could do something like the following in the onclick

If Me.yourtxtboxpassword.Value = DLookup("yourpasswordfield", "your table", "[yourusernamefield]= """ &yourtxtboxusername & """") Then
DoCmd.openform "your form name"
Else
Msgbox "They dont match"
End if
<-something like that
 
Ray

That works!! This is off topic, but can anyone recommend a good book for a beginner to learn VBA?

Thanks
 
In the code above, is it possible to add an "if" after the "else" to add additional conditions?

In this instance, I'll be assigning temporary passwords for new users which will be the same default. I'd like to add another condition so that if a new user attempts to log in with the default, lets say "password", another form will open for them to input their own password.

So the pseudo-code for that part of it would look like:

......
........
else if
(text in password field = "password") then (open form(new password))
 
you could probably use a case statement to do that. do a search on using case statements that should point u in the right direction
 
I figured out how to create a sequence of if/else statements. Now I have another question, but first an explanation.

On my login form, if a user puts in the default first time password, which is "password", a form opens(frmPassChange) with fields for the username, new password, and new password confirmation.

The username field is populated using the text that was entered in the login form by setting the control source to: =[Forms]![Login]![Text0]

The 2 password text boxes are unbound. What I want to have happen, is that when the user inputs the password twice and clicks "Submit":

If (newtextboxpassword = confirmtextboxpassword) then
Set (appropriate password field in tblEmployee equal to newtextboxpassword)
Else MsgBox "Passwords do not match. Please re-enter."
End If

I think all relevant field/table/form info is already posted above.

Can anyone please let me know what the proper syntax would be to code that?
 
think its

fieldname.value = Me.confirmtextboxpassword.value
 

Users who are viewing this thread

Back
Top Bottom