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

Running query in Form

Status
Not open for further replies.

gtree

Programmer
Aug 8, 2002
11
US
Hi,

I want to restrict access to certain forms by setting a login and password. The login and password information is stored in a table. I need to know how do I check if the login and password are correct when they press the Login button. I want to use VB code. I tried using


Private Sub cmdLogin_Click()


Dim dbs As Database
Dim rstUser_Information As Recordset
Dim strQuery As String

strQuery = "Select * From User_Information Where ((Login ='" & strLogin & "') & (Password ='" & strPassword & "'));"

Set dbs = CurrentDb

Set rstUser_Information = CurrentDb.OpenRecordset(strQuery, dbOpenDynaset)

If Not rstUser_Information.EOF Then

DoCmd.OpenForm "Commissions_Date"
rstUser_Information.Close
Set rstUser_Information = Nothing

Else
MsgBox ("Login failed")

End If

End Sub

This code seems to run even if the the login and password are wrong.

I would be grateful if someone could help me on this.
 
Hi,
Try the followin code in the Click event of your Login button.


Private Sub Login_Click()
Dim db as Database
Dim rs as Recordset
Set db=CurrentDB
Set rs= db.OpenRecordset("Select * from User_Information where login='" & Me.txtLogin & "' and password='" & txtPassword & "'", dbOpenDynaset)

If rs.RecordCount>0 then
DoCmd.OpenForm "Commissions_Date"
else
MsgBox "Login Failed. Try Again."
End If

rs.Close
db.Close
Set rs=Nothing
Set db=Nothing

End Sub

Hope this helps. Let me know what happens.
With regards,
PGK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top