Macro to check username and password match

dontgetmacros

New member
Local time
Yesterday, 22:27
Joined
Jun 8, 2011
Messages
1
So I am trying to write a macro which is able to compare a username and a password which are both in a table. Call it tblMembers. But I get the theory behind what the macro has to do but I just can't seem to get it right.

So the macro will need to lookup the username which has been entered on a login into an unbound text box.

It will then need to lookup the password which corresponds with that username in tblMembers and compare that password to the one entered in the text box. If it matches then a message box saying successful login. But then if it doesnt then a message box saying, either you're username or password is invalid, please try again.

Im been racking my brain for days to write and write but i just can't get it right.

It would you great if you could post a print screen of the macro in the design view for access 2010.

Much Appriciated
 
Add some code behind the command button on your login form to check the table something like this.

Private Sub Command0_Click()
Dim rec As Recordset2

Set rec = CurrentDb.OpenRecordset("SELECT * FROM tblMember WHERE username = """ & txtUserName.Value & """ AND password = """ & txtPassword.Value & """")
If (rec.RecordCount > 0) Then
DoCmd.OpenForm "frmMain"
DoCmd.Close acForm, "frmLogin"
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom