Results 1 to 10 of 10
  1. #1
    bopsgtir is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Dec 2010
    Posts
    62

    vba code not working with combobox

    Im having a problem with my login page. i have a simple form with username and password. i used to have the username as a textbox, and the below code worked fine, replacing combo with username, but i decided i wanted a dropdown for the usernames so i deleted the textbox and created a combobox (named combo) but now i always get the else statement MsgBox "Incorrect Login Details Please Try Again" can someone tell me where im going wrong.

    Private Sub Command7_click()
    combo.SetFocus
    If combo = "Dean Robinson" And Password = "hollie" Then
    MsgBox "Welcome Dean", vbInformation, "PDA TRACKING"


    DoCmd.Close
    DoCmd.OpenForm "Main Menu"
    ElseIf combo = "Robert Curley" And Password = "Password" Then
    MsgBox "Welcome Rob", vbInformation, "PDA TRACKING"
    DoCmd.Close
    DoCmd.OpenForm "Main Menu"
    ElseIf combo = "Colin Rushbrooke" And Password = "Password" Then
    MsgBox "Welcome Colin", vbInformation, "PDA TRACKING"
    DoCmd.Close
    DoCmd.OpenForm "Main Menu"
    Else
    MsgBox "Incorrect Login Details Please Try Again"
    End If
    End Sub

  2. #2
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    try Me.combo instead of combo

  3. #3
    bopsgtir is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Dec 2010
    Posts
    62
    No it still doest work new code reads as below. thing is if you change back to a text box it works fine.

    Private Sub Command7_click()
    Me.combo.SetFocus
    If Me.combo = "Dean Robinson" And Password = "hollie" Then
    MsgBox "Welcome Dean", vbInformation, "PDA TRACKING"
    DoCmd.Close
    DoCmd.OpenForm "Main Menu"
    ElseIf Me.combo = "Robert Curley" And Password = "Password" Then
    MsgBox "Welcome Rob", vbInformation, "PDA TRACKING"
    DoCmd.Close
    DoCmd.OpenForm "Main Menu"
    ElseIf Me.combo = "Colin Rushbrooke" And Password = "Password" Then
    MsgBox "Welcome Colin", vbInformation, "PDA TRACKING"
    DoCmd.Close
    DoCmd.OpenForm "Main Menu"
    Else
    MsgBox "Incorrect Login Details Please Try Again"
    End If
    End Sub

  4. #4
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    Password is also an undeclared variable as it is. if it's the name of a control, also put Me. in front of it.

  5. #5
    bopsgtir is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Dec 2010
    Posts
    62
    i have tried with the me.password, but still no good, its definatly down to the user name, its not reading the combo box how i want it to,

  6. #6
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    at the very beginning of your code do a
    debug.print me.combo
    debug.print me.password

    do they display in the Immediate Window the values you want?

  7. #7
    bopsgtir is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Dec 2010
    Posts
    62
    Thank you for the help ive found to problem, but not sure how to fix it, the combo box is coming back with 1 not Dean Robinson

  8. #8
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    There are 2 solutions to this. you can either
    A) change the bound column in the properties of the combobox to 2 so it stores the name
    or
    B) change your If statements to look for the ID, not the name.

    I'd do B

  9. #9
    bopsgtir is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Dec 2010
    Posts
    62
    Perfect, all working again thank you for that, i never new about the immediate window, great little tool, thank you for that.

  10. #10
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    Anytime. Glad you got it working. Please mark the thread as solved (thread tools) so that people searching the forum can find the thread and make use of it. Thank you!

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

Similar Threads

  1. VBA Code not working how it Should
    By Juan4412 in forum Programming
    Replies: 7
    Last Post: 12-07-2010, 01:59 PM
  2. VBA Code Not working
    By jo15765 in forum Programming
    Replies: 12
    Last Post: 12-03-2010, 04:01 PM
  3. Code in combobox, code in text box
    By float in forum Forms
    Replies: 3
    Last Post: 09-29-2010, 07:12 AM
  4. VB code not working
    By cwwaicw311 in forum Programming
    Replies: 17
    Last Post: 04-26-2010, 07:02 PM
  5. combobox.dropdown event not working after error
    By perlyman in forum Programming
    Replies: 1
    Last Post: 04-02-2010, 06:55 PM

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