Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2015
    Posts
    4

    Login Form Will Not Open next form once Ok is clicked please Help!

    Hi there I am kind of new to access, but i have worked with VB.net before and SQL so this VBA Language is Similar, BUT! I am stuck with something and it is wrecking my brain.
    What is happening is that when the 'User' Enters username and password, they are correct, otherwise it will show an error, but it will not open the "Switchboard" to the user's access level i.e Customer or Admin the login form just sits there and does nothing.



    The Ok button handles the user login and then checks the user's access level from there it Should open the next form and close itself but it does not.
    P.S I was working on this today and realised that emails would double up so that is not a efficient way to login so im half way through changing to username, all the search queries with the username criteria work just the msg boxes haven't changed yet
    Here Is My Code:
    Code:
    Private Sub Command1_Click()
    Dim userlevel As Boolean
    Dim Adminlevel As Boolean
    userlevel = False
    Adminlevel = False
    If IsNull(Me.email1) Then
       MsgBox "Please Enter Your Email", vbInformation, "Email Required"
       Me.email1.SetFocus
    ElseIf IsNull(Me.password1) Then
       MsgBox "Please Enter Password", vbInformation, "Password Required"
       Me.password1.SetFocus
    Else
        If (IsNull(DLookup("[Username]", "Participants", "[Username] ='" & Me.email1.Value & "' and Password = '" & Me.password1.Value & "'"))) Then
           MsgBox "Incorrect Email Or Password"
        Else
           If DLookup("[Username]", "Participants", "[Username] ='" & Me.email1.Value & "' and [Usrlvl] ='" & User & "'") Then
              userlevel = True
              Adminlevel = False
           End If
           If DLookup("[Username]", "Participants", "[Username] ='" & Me.email1.Value & "' and [Usrlvl] ='" & Admin & "'") Then
              userlevel = False
              Adminlevel = True
           End If
           If Adminlevel = True Then
               DoCmd.Close acForm, Me.Name, acSaveNo
               DoCmd.OpenForm "Admin_Switchboard", acNormal
           ElseIf userlevel = True Then
               DoCmd.Close acForm, Me.Name, acSaveNo
               DoCmd.OpenForm "Switchboard user", acNormal
           End If
       End If
    End If
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Note that code is easier to read if it is indented. Use CODE tags in post and indentation will be preserved. I fixed your post.

    Have you step debugged?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    thebigthing313 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    119

    Post

    I think you might be using DLookup wrong. There's no explicit comparison happening in your IF statements, i.e.
    If DLookup(args) = SomeValue.

    Without that, your DLookup If statements implicitly read,
    If DLookup(args) = True

    Is "Usrlevel" a field in the Participants table, and is it a Yes/No?

    Because if so, you can just test for that:

    Code:
    If DLookup("UsrLvl", "Participants", "Username = '" & Me.email1.Value & "'") Then
         'code here
    Else
         'code here
    End If
    In the future, you might want to look into naming conventions to avoid any problems caused by bad object names.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    thebigthing makes a good point. The first DLookup wrapped in IsNull Is appropriate.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Join Date
    Jan 2015
    Posts
    4
    Thanks, i tried indenting it but it didn't seem to do it so i thought it didn't want it indented, that was before i found out there were Code Tags cheers

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Is issue resolved?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Join Date
    Jan 2015
    Posts
    4
    no, unfortunately it is still doing what it was doing/is doing but ill try a couple more ideas before setting thread to solved

  8. #8
    Rawb is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    In the code, you are referencing the variables User and Admin in your DLookups, but I'm not seeing them declared anywhere. If those are the actual values you're querying for, they need to be inside the quotes like so:
    Code:
    Private Sub Command1_Click()
    Dim userlevel As Boolean
    Dim Adminlevel As Boolean
    userlevel = False
    Adminlevel = False
    If IsNull(Me.email1) Then
       MsgBox "Please Enter Your Email", vbInformation, "Email Required"
       Me.email1.SetFocus
    ElseIf IsNull(Me.password1) Then
       MsgBox "Please Enter Password", vbInformation, "Password Required"
       Me.password1.SetFocus
    Else
        If (IsNull(DLookup("[Username]", "Participants", "[Username] ='" & Me.email1.Value & "' and Password = '" & Me.password1.Value & "'"))) Then
           MsgBox "Incorrect Email Or Password"
        Else
           If DLookup("[Username]", "Participants", "[Username] ='" & Me.email1.Value & "' and [Usrlvl] ='User'") Then
              userlevel = True
              Adminlevel = False
           End If
           If DLookup("[Username]", "Participants", "[Username] ='" & Me.email1.Value & "' and [Usrlvl] ='Admin'") Then
              userlevel = False
              Adminlevel = True
           End If
           If Adminlevel = True Then
               DoCmd.Close acForm, Me.Name, acSaveNo
               DoCmd.OpenForm "Admin_Switchboard", acNormal
           ElseIf userlevel = True Then
               DoCmd.Close acForm, Me.Name, acSaveNo
               DoCmd.OpenForm "Switchboard user", acNormal
           End If
       End If
    End If
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 01-20-2014, 04:55 PM
  2. open specific form after login
    By manojsikar1 in forum Forms
    Replies: 1
    Last Post: 11-21-2012, 08:54 AM
  3. Replies: 1
    Last Post: 02-17-2011, 06:23 AM
  4. Replies: 1
    Last Post: 11-09-2010, 03:02 PM
  5. Replies: 6
    Last Post: 04-23-2010, 06:43 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums