Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2010
    Posts
    24

    Unanswered: VBA direct user to form on login

    Hi guys,

    Been having a bit of trouble with what should be a simple bit of VBA. Basically for users to access the database they must provide their own username and password (held in a table on the database - it's not for security, the database uses the UserName to identify who places orders etc...)

    It works fine by taking users who provide details that match the table to a form, but I can't seem to get it to direct users to another form if they provide the login details for 'Admin'

    Have attached the code below...for reference [Combo5] is the Username combobox on the form!

    Code:
    Private Sub PasswordBox_AfterUpdate()
    
        Dim stDocName As String
        Dim stDocName1 As String
        Dim stDocName2 As String
        Dim stLinkCriteria As String
        
        stDocName = "OptionsForm"
        stLinkCriteria = "[Username]=" & "'" & Me![Combo5] & "'"
       
        If [PasswordBox] = [Password] Then
       
            If [Username] = "Administrator" Then
            
                stDocName1 = "AdminForm"
                stLinkCriteria = "[Username]=" & "'" & Me![Combo5] & "'"
                DoCmd.OpenForm stDocName1, , , stLinkCriteria
                DoCmd.Close acForm, "OpeningForm"
        
            Else
        
                stDocName2 = "OptionsForm"
                stLinkCriteria = "[Username]=" & "'" & Me![Combo5] & "'"
                DoCmd.OpenForm stDocName2, , , stLinkCriteria
                DoCmd.Close acForm, "OpeningForm"
        
            End If
        
        Else
        
            MsgBox "The password you entered is not recognised. Re-enter your password or press Esc to cancel", vbOKOnly, "Incorrect Password!"
     
        End If
    
    End Sub
    I don't get any errors, it just doesn't do anything at all.

    /David

  2. #2
    Join Date
    Aug 2009
    Location
    Up Nort' Wi
    Posts
    140
    /Nevermind: Missed a crucial bit of your post that negates both my suggestions.

    Sam, sorry.
    Good, fast, cheap...Pick 2.

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    don't use the access logon, use the network logon, see the code bank for details, or do a Google search for dev ashish api
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Sep 2010
    Posts
    24
    Basically I'm only modifying an existing database so I don't really want to go down the route of changing how the access works.

    I'm just trying to figure out why the above code doesn't work as expected

  5. #5
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Good job this isn't for security!

    What is [Username]? Do you have option explicit set to on?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  6. #6
    Join Date
    Sep 2010
    Posts
    24
    No worries, I've managed to bodge a way around it.

    cheers

  7. #7
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    and your solution was?

    the aim of a public forum like this is that we help others. so if someone has a similar problem to you they could search and find this thread and then use your answer to resolve their problem
    I'd rather be riding on the Tiger 800 or the Norton

  8. #8
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    and your solution was?

    the aim of a public forum like this is that we help others. so if someone has a similar problem to you they could search and find this thread and then use your answer to resolve their problem
    I'd rather be riding on the Tiger 800 or the Norton

  9. #9
    Join Date
    Sep 2010
    Posts
    24
    In the end I just stuck a button on the form and in the 'On Click' event generated 2 message boxes prompting for a username and password and then referenced them against known values. If they match, then direct to the new form.

    Got the code for the prompting from the codebase and modified it to direct to a form on completion.

Posting Permissions

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