Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2009
    Posts
    28

    Unanswered: Auto Populate Form Field

    I have a form that has a text field I'd like to autopopulate when a combo box value is chosen.

    The text field is called txt_event_location with the combo called combo_event_type

    txt_event_location should pull it's value from tbl_event_type in the event_event_location field.

    So, if the combo box has Free Tune Up as a choice it should automatically put Garage in the text field.

    If anything else is chosen it should remain blank for data entry.

  2. #2
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    AfterUpdate the combo box, DLookup the value you want and put it in the text box.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    You can also link the table in the rowsource for the combobox and add the dlookup value field to the query. Then set the columns to 2 and column widths to 2";1" (or 2";0" if you want it hidden). Make sure you get the relationships setup correctly in the query (ie. 1 to many).

    Then in the AfterUpdate event of the combobox, you can set the value of the text field to the 1st column (ie. not column 0) of the combobox. ex:

    me!txt_event_location = me.combo_event_type.column(1)

    This though may add a nano-second to when the form first opens (since it has to query the combobox when it opens.) You can go with ST's recommendation of using the DLookup in the combobox AfterUpdate event:

    me!txt_event_location = DLookup("[MyLookupFieldName]","MyLookupTable","[fieldname] = '" & me!comboboxname & "'")
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  4. #4
    Join Date
    Feb 2009
    Posts
    28
    Thanks for the assistance! I tried help on DLookup but all it did was confuse me. But your ideas are a bit clearer. When I get back to it I'll give it a try and post back.

  5. #5
    Join Date
    Feb 2009
    Posts
    28
    I'm back at it. (luckily I'm volunteering)

    What I used was
    Code:
    Private Sub combo_event_type_AfterUpdate()
    Me!txt_event_location = DLookup("[event_event_location]", "tbl_event_type", "[event_event_location] = '" & Me!combo_event_type & "'")
    End Sub
    event_event_location is the field name in the table called tbl_event_type that has the data that I want to autopopulate.

    But nothing happens when i select the value in the combo box.

    I've attached the db to give you an idea what I'm trying to achieve.

    It's in frm_event. When someone chooses Garage for example I'd like the Location to automatically be Garfield Rd. which comes from the table called tbl_event_type in the event_event_location field.
    Attached Files Attached Files

  6. #6
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    "[event_event_location] = '" & Me!combo_event_type & "'")
    Event location <> event type?!?

    What do you mean by "nothing happens"? When you trace the code, you can find out what it's doing by using breakpoints... or just stepping through the code.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

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