Error With my code

crann

Registered User.
Local time
Today, 16:25
Joined
Nov 23, 2002
Messages
160
Hi
Only a beginner so have been reading many threads and kindly using sample codes to build my database.

I recently downloaded some code to create a simple login form with an option to load a different etc for Admin or Users.

When I tried to run the code I keep getting some of it highlighted telling me its incorrect.

I later found out that the person I downloaded it from identified there was a little error in code but I cant understand where it is.

Can anyone read what I have downloaded and hopefully spot what i need to change.

Thanks

Jon



Private Sub Command1_Click()
Dim UserLevel As Integer

If IsNull(Me.txtLoginID) Then
MsgBox "Please enter LoginID", vbInformation, "LoginID Required"
Me.txtLoginID.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please enter password", vbInformation, "Password Required"
Me.txtPassword.SetFocus
Else
'process the Job

If (IsNull(DLookup("UserLogin", "tblUser", "UserLogin ='" & Me.txtLoginID.Value & "'"))) Or
(IsNull(DLookup("password", "tblUser", "Password = '" & Me.txtPassword.Value & "'"))) Then

MsgBox "Incorrect LoginID or Password"
Else
UserLevel = DLookup("UserSecurity", "tblUser", "UserLogin = '" & Me.txtLoginID.Value & "'")
DoCmd.Close
If UserLevel = 1 Then
'MsgBox "LoginID and Password Correct!"
DoCmd.OpenForm "Navigation form"
Else
DoCmd.OpenForm "Customer"

End If
End If

End If
End Sub
 
Looks okay offhand, though I don't think it's complete yet. Is the code in red really on two lines? It can't be without line continuation. Are the field/form control names all correct?
 
Looks okay offhand, though I don't think it's complete yet. Is the code in red really on two lines? It can't be without line continuation. Are the field/form control names all correct?

Hi

Firstly field and forms names are correct, the system highlighted that code in red and the user I downloaded it from has posted a note to say that part of the code is not quite correct which ties in with the error, the problem is I cant really undertsand the fix its a note on YouTube :banghead:

Thanks
Jon
 
Can you post the db here?
 
Hi

Firstly field and forms names are correct, the system highlighted that code in red and the user I downloaded it from has posted a note to say that part of the code is not quite correct which ties in with the error, the problem is I cant really undertsand the fix its a note on YouTube :banghead:

Thanks
Jon

The Fix message read:

you can fix the code by combining crtteria LoginID and Password in one criteria under one DLookup.

Jon
 
Well, there's certainly a logical error there, but it wouldn't cause an error in the code.

By the way, I deleted your duplicate thread. Please don't post the same question twice.
 
Paul
Ok sorry about sencond post wasnt sure if I had posted in right area.

Not sure how to attach a db
 
Paul

db attached I hope. literally just trying to get this Login Working


Thanks

Jon
 

Attachments

There's nothing highlighted in this code, and it runs without error. Are you describing the fact that it doesn't do what you want? It wouldn't because as written it basically checks that a user exists with that login and that somebody has the password. It doesn't match them together. I'd use a recordset, but here's line from an old db that is more logically what you want:

If DLookup("UserPassword", "tblUsers", "UserName = '" & Me.txtUserID & "'") <> Me.txtPW Then

Note how it's getting the password from the table for the logged in user, and comparing that to the password that was input.
 
Paul

Yes basically I mean its not doing what I want when I load the login form and enter login details always returns, Run-time error '13': type mismatch.

Unfortunately I dont have the skills to really make sense of your reply this is the problem I have.

When someone sends me amended code Im still nnot sure what Im suppose to be changing, adding or removing.

I should probably start again from the start.

Thanks Jon
 
The type mismatch occurs because you look up a text UserSecurity value (like "Admin") and try to put it into a variable declared as Integer, which can only take a number.
 

Users who are viewing this thread

Back
Top Bottom