Consulting

Results 1 to 8 of 8

Thread: Error 2001 !Important!

  1. #1
    VBAX Newbie
    Joined
    Mar 2010
    Posts
    3
    Location

    Exclamation Error 2001 !Important!

    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
    [vba]
    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
    [/vba]

    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 =)
    Last edited by ph03nix; 03-26-2010 at 03:52 PM.

  2. #2
    VBAX Contributor
    Joined
    Feb 2007
    Posts
    126
    Location
    I believe the general format for DLookup() is

    [VBA]Look up the _____ field, from the _____ table, where the record is _____[/VBA]

    see link below for various examples ...

    http://www.tek-tips.com/faqs.cfm?fid=4978

  3. #3
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,297
    Location
    Do you have to use Dlookup?
    As a VBA recordset works well.

  4. #4
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    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:

    [VBA]Search_Result_Username = DLookup("[Entrance Allowance]", "db_Users", ' & [Search_User] & ') [/VBA]
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  5. #5
    VBAX Newbie
    Joined
    Mar 2010
    Posts
    3
    Location
    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:
    [vba]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[/vba]

    Sorry for the German ^^ It is the last part of the code
    thx for all the help here =)

  6. #6
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    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?
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  7. #7
    VBAX Newbie
    Joined
    Mar 2010
    Posts
    3
    Location
    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
    [VBA]str_LoginRights = DLookup("bn_UsernameRights", "db_Users", "[lng_UsernameID]=" & Me.cboUsers.Value)[/VBA]
    before it was [VBA]str_MyUsernameID = DLookup("bn_UsernameRights", "db_Users", "[lng_MyUsernameID]=" & lng_UsernameID)[/VBA]
    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 =/

  8. #8
    VBAX Expert Imdabaum's Avatar
    Joined
    Jun 2006
    Posts
    652
    Location
    Quote Originally Posted by ph03nix
    [vba]
    ***** lng_MyUsernameID = Me.cboUsers.Value

    str_MyUsernameID = DLookup("bn_UsernameRights", "db_Users", "[lng_MyUsernameID]=" & ****** lng_UsernameID)

    End Sub[/vba]
    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)
    Someday I'll understand everything...
    Even then...I'll still pretend I'm a beginner.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •