Run a macro based on an iif statement

davebhoy

Dave
Local time
Today, 17:52
Joined
Aug 1, 2006
Messages
37
Hi there

I'm new to VBA coding and think I have a straight forward question

I want to run a macro based on an if statement built in to a click procedure on a button called "Command8". Basically if username = password then run the macro, otherwise show message box "Login Failed".

Thanks in advance

Dave
 
Sorry Colin

should be if password = pword.

password is the stored password in an query while pword is the textbox he's entering the password to login
 
I've tried the following code but brackets are causing an error!

Private Sub Command8_Click()
On Error GoTo Err_Command8_click

iif([password]=[pword],DoCmd.RunMacro("Create Data",,),Msgbox("Login Failed",vbOKOnly,"Invalid Login",,)
 
Sorry, I now changed the code. Could you tell how to declare password and pword where the questions marks are below. Password is from the password field in the form's query and pword is the textbox on the form where he types his password. Thanks.

Private Sub Command8_Click()
On Error GoTo Err_Command8_Click

Dim password As String
Dim pword As String

password = ????????
pword = ????????

If password = pword Then

DoCmd.RunMacro "Create Data"

Else

MsgBox "Login Failed", vbOKOnly, "Invalid Login"

End If
 

Users who are viewing this thread

Back
Top Bottom