Results 1 to 4 of 4
  1. #1
    batowl is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Dec 2010
    Posts
    86

    Combo Box, Text Box Based on Selection from Other Combo Box

    I have a form where I want a combo box to populate based on the selection in another combo box. I also want a text box to populate based upon the selection in a combo box.

    For the combo box - combo box situation: if my user chooses "Yes" in combo box 1, I want combo box 2 to automatically populate with "N/A". If they choose anything else in combo box 1 ("No" or "Unknown" are other options) I want combo box 2 to be left alone for the user to populate themselves ("Yes", "No", "Unknown" are other options they can choose from).

    For the text box - combo box situation: if my user chooses "water" or " food" from combo box A, I want text box A to automatically populate with "N/A". If they choose "Other" from combo box A, I want text box A left alone so that the user can type themselves.

    Any suggestions? This is something I have been trying to figure out for ages... it is the last change I need to make before this db goes live (finally). Thanks.

  2. #2
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    Your solution lies within visual basic.

    For the combo box - combo box situation:

    Code:
    Private Sub [Combo Box 1]_Change()
    if [combo box 1]="Yes" then
    [combo box 2]="N/A"
    endif
    End Sub
    For the text box - combo box situation:

    Code:
    Private Sub [Combo Box A]_Change()
    
    if [combo box A]="Water" or [combo box A]="Food" then
    [Text Box A]="N/A"
    endif
    
    End Sub
    To put the code in (you need to repeat this once for each control):

    1. Right click on the control on your form
    2. Click Properties
    3. Click Event
    4. Double click in the empty field next to On Change
    5. It should now read [Event Procedure], if so click on the little button with the three dots
    6. This opens the visual basic code builder, copy and paste the above code (assuming the control names are correct) without altering any other text
    7. click the exit button on the code builder to return to access

    That *should* do it

  3. #3
    batowl is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Dec 2010
    Posts
    86
    Thank you - this works great. I appreciate it. One problem: the data that is getting automatically filled in is not being recorded in the table, so that when I exit the form and re-enter, all that automatically entered data is now gone. I think this has to do with the record source on the form, which is my table. When I click on the properties of the form, record source, ... to invoke the Query Builder, my table is present but all of the fields to populate the query are blank. How do I fix this so that the automatically added fields are kept in the form when I exit and enter (and entered into the table)?

  4. #4
    batowl is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Dec 2010
    Posts
    86
    Ok, I opened the query builder and populated it with all the fields on the form. Thank you for your help

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

Similar Threads

  1. Replies: 8
    Last Post: 01-25-2012, 02:07 PM
  2. Replies: 33
    Last Post: 01-13-2012, 07:44 AM
  3. If Statement based on Combo Box selection
    By Jojojo in forum Programming
    Replies: 2
    Last Post: 11-02-2011, 05:42 PM
  4. Replies: 4
    Last Post: 01-24-2011, 07:11 PM
  5. Replies: 1
    Last Post: 08-26-2009, 10:45 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