Login/Password Question

J

James C.

Can someone help??? I am trying to get the following code to work and keep
getting an error. The code takes a username & password input from a form,
compares it to a list of usernames and passwords in a table before allowing
the person to login.

Here is the code -------------------------------
Private Sub LoginScript()
Dim db As Database
Set db = CurrentDb()
Dim rs As Recordset
Dim strUser As String
Dim strPassword As String

txtUsername.SetFocus
strUser = txtUsername
txtPassword.SetFocus
strPassword = txtPassword

If Not IsNull(Me.txtUsername) And Not IsNull(Me.txtPassword) Then
Set rs = db.OpenRecordset("Select * from LoginSecurity where Username =
'" & strUser & "' And Password = '" & strPassword & "'", dbOpenSnapshot)

If rs.EOF Then
MsgBox ("This worked")
Else
MsgBox ("This didnot work")
End If

End If
--------------------------------------------------\

I am getting an error "Type Mismatch" when it hits the following line:

Set rs = db.OpenRecordset("Select * from LoginSecurity where Username = '" &
strUser & "' And Password = '" & strPassword & "'", dbOpenSnapshot)

Any ideas?
 
R

Rob Parker

If you're using a version of Access after A97, and you have a reference to
an ADO library higher in your reference list, you'll get this error. You
can fix it by re-ordering the references, but by far the better way is to
disambiguate the declarations of db and rs, as follows:

Dim db As DAO.Database
Dim rs As DAO.Recordset

HTH,

Rob
 
A

Allan Murphy

James

I use a screen called frm_main for the users to enter their userid and
password then validate the entries using the following code

----- tbl_users contains user_id, access_level password, and expiry_date of
the password.
then for a vaild userid and password I then check the expiry date of
the password and force the user to change their password
before allowing access to the database.
I also go one step further by checking the users access level and
display the relevant menu items depending on their access level.

Function check_user()

Dim various_checks As Integer
Dim current_password As Variant

various_checks = 0

' test for valid user_id
If IsNull(DLookup("[user_id]", "tbl_users", "user_id =
forms!frm_main!user_id")) Then

various_checks = 1 'invalid user id
Else

current_password = DLookup("[passwords]", "tbl_users", "user_id =
forms!frm_main!user_id")

If current_password = Forms!frm_main!password Then

various_checks = 2
Else
various_checks = 1
End If ' valid password
End If 'test for valid user id
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top