Autopopulate Field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hkim8392126
    New Member
    • Nov 2008
    • 2

    Autopopulate Field

    I've been searching and reading the forum, but with no success to find what I was looking for. I am trying to autopopulate a field in a form. I am not sure if I need to create a query or table to do this so please let me know how I would be able to perform this task. First, I have a table with field 1: units and field 2: has the corresponding battalions. I have a form that has the combo box for units and battalions. I want the battalion combo box to autopopulate the correct battalion based on what unit combo box is chosen. I hope I have been clear enough. Please let me know if I need to create a table or something else to do this. I don't know much about VB so if it could only be done in VB, please walk me through it. Thanks

    Kim
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    The way I do this is to use the AfterUpdate event of the combo box to set the source for the other combo box. This is just for example:

    private sub Combo1_AfterUpd ate()
    dim strSQL as String

    if not (isnull(combo1) ) then
    strSQL = "SELECT Battalion FROM MyTable WHERE Units = """ _
    & Combo1 & """"
    combo2.RowSourc e = strSQL
    end if
    end sub

    So your combo boxes have to have a Row Source Type of Table/Query. Also, I set the combo boxes to Limit To List and the Not In List event to:
    Private Sub Combo1_NotInLis t(...)
    Response = accDataErrConti nue
    end sub

    That's just to supress the Access msg.

    Comment

    • hkim8392126
      New Member
      • Nov 2008
      • 2

      #3
      Where to input?

      So how do I put these codes into vba? I open up vba, but i'm not sure how to input it.

      Comment

      • ChipR
        Recognized Expert Top Contributor
        • Jul 2008
        • 1289

        #4
        Go to your Combo Box properties, Event tab, click the AfterUpdate, click the elipsis, click Event Procedure. That will take you to the appropriate Form and Procedure in your editor.

        Comment

        Working...