View Full Version : Error 2001 !Important!
ph03nix
03-26-2010, 03:21 PM
Hey, Im tryin to create something like a login, but always when I go to use DLookup to search the Table I get a error 2001 can't really tell why
Private Sub Command11_Click()
Dim Search_Result_Username As Variant
Dim Search_Result_Password As Variant
Dim Search_User As String
If IsNull(Me!Text2) Then
MsgBox "Please enter Username", vbOKOnly, "Invalid Username"
Else
Search_User = Me!Text2
End If
Dim Search_Password As String
If IsNull(Me!Text6) Then
MsgBox "Please enter Password", vbOKOnly, "Invalid Password"
Else
Search_Password = Me!Text6
End If
If IsNull(Search_User) = False Then
Search_Result_Username = DLookup("[Entrance Allowance]", "db_Users", [Search_User])
If (Search_Result_Username) = False Then
MsgBox [Search_Result_Username], vbOKOnly, "Found"
End If
Else
End If
If IsNull(Search_Password) = False Then
Search_Result_Password = DLookup("[Entrance Allowance]", "db_Users", Search_Password)
If (Search_Result_Password) = False Then
MsgBox [Search_Result_Password], vbOKOnly, "Found"
End If
Else
End If
End Sub
Text2 and Text6 are Textboxes
Entrance Allowance is a Yes/No Field
I have to do this as a project for school so fast help is appreaciated
Thanks in Advance =)
itipu
03-27-2010, 12:28 AM
I believe the general format for DLookup() is
Look up the _____ field, from the _____ table, where the record is _____
see link below for various examples ...
http://www.tek-tips.com/faqs.cfm?fid=4978
Do you have to use Dlookup?
As a VBA recordset works well.
CreganTur
03-29-2010, 07:46 AM
You're getting an error because you aren't fully qualifying your variables in the DLookup function. You need single quotes around the variable to indicate that it's a string, like this:
Search_Result_Username = DLookup("[Entrance Allowance]", "db_Users", ' & [Search_User] & ')
ph03nix
03-29-2010, 12:04 PM
Well I kinda solved that Problem now the thing with the quotes worked thx =D
but now Im having a problem with the Usage Rights =/ I restructured everything and now I have a Userrights Field with Admin and User defined in it
I want to open a different form for an Administrator as for a User, and now I have to use DLookup again and now Im having a problem accessing the Username Rights in combination with Username
The entire Code is as following:
Option Compare Database
Private intLogonAttempts As Integer
Private Sub Form_Open(Cancel As Integer)
'Fokus auf die Combobox Username setze
Me.cboUsers.SetFocus
End Sub
Private Sub cboUsers_AfterUpdate()
'Nach selektieren der Combobox den fokus auf PasswordFeld setzen
Me.TextPassword.SetFocus
End Sub
Private Sub cmd_Login_Click()
'Überprüfen ob Combobox leer ist
If IsNull(Me.cboUsers) Or Me.cboUsers = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboUsers.SetFocus
Exit Sub
End If
'Überprüfen ob PasswordFeld leer ist
If IsNull(Me.TextPassword) Or Me.TextPassword = "" Then
MsgBox "Please enter Password.", vbOKOnly, "Invalid Password"
Me.TextPassword.SetFocus
Exit Sub
End If
'Wert des PasswortFeld mit db_Users vergleichen
'um zu sehen ob diese mit der Combobox übereinstimmt
If Me.TextPassword.Value = DLookup("str_UsernamePassword", "db_Users", _
"[lng_UsernameID]=" & Me.cboUsers.Value) Then
lng_MyUsernameID = Me.cboUsers.Value
'Logon Screen ConTable schliessen
DoCmd.Close acForm, "ConTable", acSaveNo
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
"Invalid Password!"
Me.TextPassword.SetFocus
End If
'Bei dreifachem falschem Eingeben des Passwortes Programm schliessen
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "Restricted Access: Invalid Password", _
vbCritical, "Restricted Access!"
Application.Quit
End If
'überprüfen der Rechte des einloggenden Users
str_MyUsernameID = DLookup("bn_UsernameRights", "db_Users", "[lng_MyUsernameID]=" & lng_UsernameID)
If str_MyUsernameID = "Admin" Then
DoCmd.Close acForm, "ConTable"
DoCmd.OpenForm "Administrator_Page", acNormal
Else
If str_MyUsernameID = "User" Then
DoCmd.Close acForm, "ConTable", acSaveNo
DoCmd.OpenForm "User_Page", acNormal
End If
End If
End Sub
Sorry for the German ^^ It is the last part of the code
thx for all the help here =)
CreganTur
03-30-2010, 05:12 AM
I want to open a different form for an Administrator as for a User, and now I have to use DLookup again and now Im having a problem accessing the Username Rights in combination with Username
Exactly what problem are you experiencing?
ph03nix
03-30-2010, 05:46 AM
Now I am getting an error 2467 The Expression you entered refers to an object that is closed or doesn't exist
When I press the debugg button it highlights
str_LoginRights = DLookup("bn_UsernameRights", "db_Users", "[lng_UsernameID]=" & Me.cboUsers.Value)
before it was str_MyUsernameID = DLookup("bn_UsernameRights", "db_Users", "[lng_MyUsernameID]=" & lng_UsernameID)
But I noticed that couldnt be right =/
str_Login_Rights I declared in a Module as a string
I never had that error before =/ And googling really didnt help because it looks like it could be various things =/
Imdabaum
03-30-2010, 01:38 PM
***** lng_MyUsernameID = Me.cboUsers.Value
str_MyUsernameID = DLookup("bn_UsernameRights", "db_Users", "[lng_MyUsernameID]=" & ****** lng_UsernameID)
End Sub
Not sure if you've tried this, but you don't seem to be using the same variable that you declared in your code.
Try
str_MyUsernameID = DLookup("bn_UsernameRights", "db_Users", "[lng_MyUsernameID]=" & lng_MyUsernameID)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.