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.
 
Two things I see to help correct this problem...

#1 Change your connection constant from dbOpenDynaset to dbOpenSnapshot. It will probably run .01% faster, but hey, what the heck!

#2 Change the following code...

If Not rstUser_Information.EOF Then

TO...

If Not rstUser_Information.BOF Then

#3 And most importantly, your SQL code doesn't look right. I changed your SQL below...

"Select * From User_Information Where Login ='" & strLogin & "' AND Password ='" & strPassword & "';"

Hope that resolves it.

Gary
gwinn7
A+, Network+
 
Oops, okay THREE things to help. :)

Gary
gwinn7
A+, Network+
 
Hi gwinn7,

Thanks a ton! The problem was the SQL code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top