Results 1 to 2 of 2
  1. #1
    caddcop is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2011
    Location
    Upper Marlboro, Maryland, USA
    Posts
    57

    How to Populate a Combo Box from Query in Code

    I am trying to build a form that allows someone to scroll through records and on certain fields, limit them to choices in a combo box.


    To do this, I need to compare the value of one of the fields in a record, with the choices in the combo box, and make them match. In some cases, the field will be blank or NULL and that is acceptable.
    To complicate it further, some of the form fields are on sub-forms.
    I have used some combo boxes before that are built from a table or query automatically using the Properties dialog box to set the combo box to build itself.
    What I could not figure out, was how to, in or out of code, populate a combo box with data from a table or query, where there are no blank fields automatically but to still allow a blank selection.

  2. #2
    caddcop is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2011
    Location
    Upper Marlboro, Maryland, USA
    Posts
    57
    I decided to reply to myself rather than edit the original post.
    I found a method that works and it is clever enough to share:
    I added a text box that reads from the field in the table that I want to appear in the combo box. Eventually, this text box will be set as Visible = No, but during testing, is set to Yes.
    The combo box uses the query as its source. When the form's current event runs, I check to see if the text box is null. If it is not, I assign the value of the text box to the combo box. If it is null, I set the combo box value back to null.
    I already have another use for a similar item. There is a field representing a yes no value, but the database developer is using zero or 1. To use a check box on the form, I'm using a hidden text box and linking a check box to it in code.

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

Similar Threads

  1. Replies: 9
    Last Post: 07-20-2015, 10:55 AM
  2. Replies: 4
    Last Post: 01-24-2011, 07:11 PM
  3. Use Combo Box to Populate Form
    By gracysaurus in forum Forms
    Replies: 1
    Last Post: 08-09-2010, 02:40 PM
  4. Auto-Populate Combo box
    By vincenoir in forum Forms
    Replies: 3
    Last Post: 10-14-2009, 07:06 AM
  5. Populate Combo Box
    By wes28 in forum Programming
    Replies: 1
    Last Post: 03-04-2009, 06: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