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 referencing

Status
Not open for further replies.

nathanheyer

Technical User
Sep 6, 2001
5
AU
I want to reference a table to have a password funtion but its not working...
I have a "login" screen and want the button the check that the username and password are correct please help..

Nathan
 
You can modify this to fit your needs:

Code:
Private Sub cmdLogin_Click()

Dim dbs
Dim RST
Dim strSQL
Dim PW 'Password
Dim frm As Form
Set dbs = CurrentDb

User = Me.txtUser
PW = Me.txtPW
strSQL = "SELECT [tblUser].[UserName], [tblUser].[Password],[tblUser].[rights],[tblUser].[Menu] FROM tblUser WHERE ((([tblUser].[UserName])=" & Chr(34) & User & Chr(34) & "))"
'Open the recordset based on the SQL statement
Set RST = dbs.OpenRecordset(strSQL)
With RST
  'If the password matches the one stored in the recordset
  If !Password = PW Then
    'Notify the user of a successful log in
    MsgBox "Welcome " & User
    DoCmd.OpenForm RST!Menu
    DoCmd.Close acForm, "frmLogin"
  Else
    'Wrong password or user doesn't exsist
    MsgBox "Nope"
  End If
End With
End Sub
Tyrone Lumley
augerinn@gte.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top