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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Coding (Accept User-id/Password from a dialog box)

Status
Not open for further replies.

CLOS

MIS
Jan 30, 2002
23
0
0
US
Help Anybody!

I have a table that holds a user-id and password. I
also have a dialog box that accepts the userid/password.
Now, how do I write the VBA code that goes behind the
button that searches the table for the user-id/password.
For example, the table name is 'USERS'. Thanks!
 
I would look up the OpenRecordset in help. That will show you how an example of code that will run a query against a table in code. I would then look at the IF... THEN... ELSE function to control what to do next.

IF rst.password = MyForm.txtpwd THEN
'allow use
ELSE
'Loser message
END IF
Terry M. Hoey
 
Hi there. My solution is not case sensitive. If you want a case sensitive result for the password, remove the two Lcase commands. :)
Here goes:
In your table called Users include a text field called UserId and one called Pword (it's unwise to use Password, since it's a reserverd word)

Create a new form and add a text box called text1 with a label of "User".
Add a text box called text2 with a label of "Password".
In the property Input Mask of the text2 control type Password (this will display your password as asterisks, while holding the value as the typed value)

Add a command button with a caption of "Logon". Name the button cmdLogon.

Now we're ready to go. Paste the following code in the "On Click" event of Logon command button.

Code:
Private Sub cmdlogon_Click()
On Error GoTo Err_cmdlogon_Click
    Dim strPassword As String
    strPassword = DLookup("[Pword]", "Users", "[UserId] = '" & Text1 & "'")
    If LCase(strPassword) = LCase(Text2) Then
        MsgBox "User logged on successfully.", vbInformation
    Else
        MsgBox "Can't log on. Username and password do not match. " _
        & Chr(13) & "Please try again", vbCritical
    End If
    
Exit_cmdlogon_Click:
    Exit Sub

Err_cmdlogon_Click:
    MsgBox Err.Description
    Resume Exit_cmdlogon_Click
    
End Sub

Good Luck Escolar X-)


 
this is much easier...

make a combo box that contains the userid and password (look them up from your table) then set the column count of the box to display only the userid's and hide the passwords...

put a text box below and then have them verify the password matches the userid from the dropdown menu above...

If txtUserID.Text <> cboUserPass.Column(2) Then

sorry = MsgBox(&quot;Wrong Password! Try again!&quot;, vbOKOnly, &quot;Please try again!&quot;)

Else
modcuruser.curuser = Combo2.Column(3)'this is a variable
Me.Visible = False 'u can use to keep
DoCmd.OpenForm &quot;MainMenu&quot;, acNormal 'track of who is
DoCmd.Close acForm, &quot;openmenu&quot; 'logged in

End If land of milk and Honey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top