Results 1 to 7 of 7
  1. #1
    jparker1954 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    85

    Question Entries made to Combo Boxes

    I've got a form that uses a combo box to help users fill in information from a table. The ROW SOURCE says something like:

    SELECT DISTINCT Info.Criteria1, Info.Criteria2, Info.Criteria3 FROM Info WHERE Info.Criteria3="XYZ";

    This works great for the selections I want users to have; HOWEVER, is there a way to combine this with a code that will have the combo box field automatically default to the information from the previous record if no changes are needed, yet still allow for the dropdown selections if changes are wanted?

  2. #2
    randman1 is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2009
    Posts
    25
    The combobox would have to be unbound from any ControlSource. It will contain no value when the form is first opened but retain the value that was selected until it was changed or the form is closed.

    This may be useful for data entry where the user is adding new records but not very useful for displaying existing records as the unbound combobox would not display the existing value. You would also have to set the value to the field in the BeforeUpdate event.

    Code:
    Private Sub Form_BeforeUpdate
        Me!FieldName = Me.ComboboxName
    End sub

  3. #3
    jparker1954 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    85
    Thank you for the reply. If I have to keep one or the other, I need to keep the dropdown list. I was just hoping that there was a way to set the value of the dropdown based upon the prior record. However, your comment may help me with other issues along the way. Thanks again!

  4. #4
    randman1 is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2009
    Posts
    25
    I'll clarify. The above method will still provide the dropdown list as there are no changes to the RowSource property.

    RowSource property of the combobox is where your query is (SELECT DISTINCT Info.Criteria1, Info.Criteria2, Info.Criteria3 FROM Info WHERE Info.Criteria3="XYZ")

    ControlSource property of the combobox is the field to which the control is linked.

    When you have an unbound control, it has no initial value when the form is opened unless you set the DefaultValue property. The user can still select from the choices though. The choice however, will not be automatically applied to the underlying table because its not "bound" to a field. The code in the BeforeUpdate sub is required to set the contents of the combobox to the desired field in the table.

  5. #5
    jparker1954 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    85
    Unfortunately, I tried this code, but if I try to change a value in a combo box it changes ALL the values in ALL the records to that changed value. I need something that will leave prior values as they were and only make changes to the new record. Got any ideas for that?

  6. #6
    randman1 is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2009
    Posts
    25
    My apologies. The code needs to go in the BeforeInsert event rather than BeforeUpdate. This way, it will only apply the combobox value to new records instead of any record that is changed.

    Do you only use the form to enter new records or is it also used to maintain existing records?

  7. #7
    jparker1954 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    85
    I use it to enter and maintain records. Actually, I found this site http://support.microsoft.com/kb/210236 and it solved my problems. Thanks,

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

Similar Threads

  1. Replies: 9
    Last Post: 06-04-2014, 10:45 AM
  2. How do I add multiple table entries using check boxes?
    By avarusbrightfyre in forum Access
    Replies: 3
    Last Post: 10-21-2010, 01:09 PM
  3. Replies: 3
    Last Post: 05-25-2010, 02:16 PM
  4. combo boxes
    By thewabit in forum Forms
    Replies: 7
    Last Post: 01-01-2010, 08:51 PM
  5. combo boxes
    By labrams in forum Forms
    Replies: 0
    Last Post: 04-20-2006, 09:28 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