Results 1 to 6 of 6
  1. #1
    Mely is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    3

    VBA Help: How to auto populate a Text Box based on tow or more Combo Boxes


    I am very new at this and not very familiar with VBA, and hope someone can help me here. I need the Text Box to automatically update when values are chosen from 2 or more Combo Boxes. This is the code I have in my text box properities [Event Procedure]. If I put the code OnClick, it works but I want the value on the text box to show up automatically without having to click.
    Code:
    Private Sub Value_AfterUpdate()
     
    If Me.ComboBox1.Value = "Director" And Me.ComboBox2.Value = "NATIONAL" And Me.ComboBox3.Value = "Oral" Then  TextBox.Value = "1"
       
        ElseIf Me. ComboBox1.Value = "CFO" And Me.ComboBox2.Value = "NATIONAL" And ComboBox3 = "Oral" Then       
        TextBox.Value = "2"
     
        Else
            [TextBox] = "0"
     
        End If
     
    End Sub
    Thank you.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I would expect it in the after update event of the 3 combos. I'd actually have a form level function that did it, and call it from those 3 events.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Mely is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    3
    Thank you for the response Paul. Should I have the same code in each combo box? Would you mind expounding a little bit? I am not very familiar with a form level function, how should I proceed?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can have the same code behind each combo. For ease of maintenance, I'd use the function. That way if/when you need to edit it, you only have to change it in one place. Here's a primer:

    http://www.baldyweb.com/Function.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Mely is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    3
    Thank you so much Paul.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help, and welcome to the site!
    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: 9
    Last Post: 06-04-2014, 10:45 AM
  2. Replies: 7
    Last Post: 12-29-2011, 10:13 AM
  3. Text/Combo boxes and Check box PLEASE help!!!!
    By PAS123 in forum Programming
    Replies: 4
    Last Post: 12-15-2011, 01:17 PM
  4. Update Tables from Combo Boxes in a Form
    By RedWolf3x in forum Access
    Replies: 3
    Last Post: 11-03-2011, 08:07 AM
  5. Update Two fields (text boxes) Form
    By j2curtis64 in forum Forms
    Replies: 11
    Last Post: 07-06-2011, 08: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