Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password with If then statement for validation and action

Status
Not open for further replies.
Dec 5, 2005
40
US
Hi, I have a form that will have a place for the user to enter a password. I want to use visual basic to compare what the user enters against the field on the form (hidden) and run macro 1 if it matches, run macro 2 if it does not.

Any help would be appreciated.
Thanks

field names
PIN(field name where user enters a PW)
UserPW (defined in table and hidden on form)
macro1 (will run a query to add data to a table)
macro2 (will bring up a form saying wrong PIN, try again)
 
1) Add a button to your form for the user to click after they enter the password.
2) In the buttons Click Event put...

If Me.PIN = Me.UserPW Then
DoCmd.RunMacro "Macro1"
Else
DoCmd.RunMacro "Macro2"
End if

ProDev, Builders of Affordable Software Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
How are ya nickrugado . . .

Looking up in the table instead and providing automation, try the following in the [blue]BeforeUpdate[/blue] event of [blue]PIN[/blue] ([blue]you![/blue] substitute proper names in [purple]purple[/purple]):
Code:
[blue]   Dim Cri As String
   
   Cri = "[UserPW] = '" & Me!PIN & "'"
   If Me!PIN = Nz(DLookup("[UserPW]", "[purple][b]TableName[/b][/purple]", Cri), "") Then
      DoCmd.RunMacro "Macro1"
   Else
      DoCmd.RunMacro "Macro2"
      Me!PIN = Null
      Cancel = True
   End If[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
 
nickrugado . . .

I've noticed you've duplicated this thread with thread705-1439364 in the VBA forum, just 3 minutes later.

Its bad policy to post the same content in more than one forum! In my own words, I call it Gang Banging the forums!

Tipsters will be less inclined to answer if this is noticed . . . let alone the possibility of having the thread [red]red-flagged[/red] and removed.

A little more discretion in your forum choices is all thats needed . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top