Results 1 to 12 of 12
  1. #1
    element32d is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    24

    Combo Box If Then statement finding certain text in input

    I'm not very good at VBA code yet, but I think this is possible:

    There's a combo box that a user selects something from a list and I want it so that if the user selects something with "A" in it, then when they click the button it goes to form letter "A" or if the user selects something with letter "B" in it, then when they click the button it goes to form "B".



    Help would be appreciated, thank you!

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    How about:

    Code:
    If Me.ComboName = "A" Then
      'open the a form
    ElseIf Me.ComboName = "B" Then
      'open the b form
    End If
    Though I suspect there's more to it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    element32d is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    24
    Quote Originally Posted by pbaldy View Post
    How about:

    Code:
    If Me.ComboName = "A" Then
      'open the a form
    ElseIf Me.ComboName = "B" Then
      'open the b form
    End If
    Though I suspect there's more to it.
    Yea sorry I should have used a better example. The choice is longer than just "A" or "B". So the user can choose something like CA003 or CB003 and I want the code the find that letter or string of letters somewhere in that whole text.

    So basically, it contains A or B somewhere in the choice. Is this more clear?

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Check out the InStr() function, which will test for a given letter.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    element32d is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    24
    I found that in my google searches, although most if not all results dealt with excel and I wasn't sure if it could translate into combo boxes for access or not.

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sure; this:

    If Me.ComboName = "A" Then

    becomes

    If InStr(1, Me.ComboName, "A") > 0 Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    element32d is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    24
    I'll try that out tomorrow and give you feedback once I get it to work, thanks a lot!

  8. #8
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    element32d is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    24
    I tried implementing your suggested code. It's giving me a "method or data member not found" error and highlighting combobox name in the me.combobox part of the if statement. My combobox name is "ID#" so that line of code currently looks like
    Code:
    If InStr(1, Me.ID#, "55-1") > 0 Then
    The event procedure is currently in the "on click" portion of the button if that matters.

  10. #10
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    With the inadvisable symbol in the name, you'll generally have to bracket the name: [ID#]
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    element32d is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    24
    Ah yes, I just came in here to say I renamed the combobox name and it worked perfectly. But the brackets will be the better solution. Thank you very much.

  12. #12
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem. In my opinion not using spaces or symbols is the better solution.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 05-23-2012, 08:54 AM
  2. Replies: 11
    Last Post: 12-25-2011, 04:33 PM
  3. Replies: 3
    Last Post: 09-20-2011, 11:54 AM
  4. Replies: 15
    Last Post: 04-01-2011, 11:41 AM
  5. Finding highest value in a text field
    By cdominguez in forum Queries
    Replies: 3
    Last Post: 06-02-2009, 09:39 AM

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