Results 1 to 9 of 9
  1. #1
    shuddle is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    43

    Auto fill text box by Combo box

    I know this is posted a lot but for some reason I can't seem to figure out what is wrong with my code.



    Private Sub Location_AfterUpdate()
    Me.LocState = Me.LocCity.Column(1)
    End Sub


    All I am trying to do is auto populate the state after the city has been entered.

    The city combo box is based off a lookup table with the city and state as fields.



    Am I missing a step somewhere?

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    The code should be in the after update event of the city combo box.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    You haven't updated that control though have you, you have updated the combo?
    Are you saying you have a lookup field in the table for location?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi

    You say:- "The city combo box is based off a lookup table with the city and state as fields."

    The lookup table should be as follows:-
    -tblStates
    StateID - PK - Autonumber
    State
    City

    Which makes this part wrong:-
    Me.LocState = Me.LocCity.Column(1)

    It should read:-
    Me.LocState = Me.LocCity.Column(2)

    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  5. #5
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    I think you should clarify the table structure for the the lookup table (city\state) and also for the actual data table where you store this location. Do you store both the city and the state in the data table? Have you considered storing just the foreign key (StateID in Mike's post #4 above)? If you do that then there is no need to have any code to display the city and the state on your data entry form, simply set the control sources of those textboxes to the appropriate combo column index and they will update automatically when you change the combo.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    shuddle is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    43
    Thanks for all the good insight.

    I'm getting the error "Compile error: Method or data member not found" highlighting the .Column


    My look up table: LookupTbl_City has
    StateID as the primary key
    City
    State



    LocCity lookup settings are

    Row Source LookupTblCity
    Bound Column 2
    Column Count 3
    Column Heads No
    Column Widths 0;1;0.5

  7. #7
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Row Source LookupTblCity
    Bound Column 1
    Column Count 3
    Column Heads No
    Column Widths 0;1;0.5
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  8. #8
    shuddle is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    43
    It's resolved. It was a naming issue similar to what #2 Davegji pointed out. Thank you everyone for your help.

  9. #9
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    @shuddle: the question I asked in post # 5 was if you want\need to save both City and State in your data table or just the CityState foreign key (StateID from your post 6) which would give you both city and state via a query or dLookup whenever needed. In that case you don't need any code in the after update event, just set the control source of the textbox where you want to display the state as [cboStateId].Column(2) (where cboStateId is the name of the combo bound to the field storing the StateID FK).

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 2
    Last Post: 06-30-2016, 10:51 AM
  2. Combo Box to auto fill text box - problem
    By mmaurigi in forum Programming
    Replies: 6
    Last Post: 03-29-2016, 09:35 AM
  3. Text boxes auto fill after combo box update
    By royalbridge in forum Access
    Replies: 11
    Last Post: 07-13-2015, 11:56 AM
  4. Replies: 5
    Last Post: 11-09-2012, 04:18 PM
  5. auto fill text box from dependent combo box
    By tommyried in forum Access
    Replies: 6
    Last Post: 06-17-2012, 03: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