Results 1 to 12 of 12
  1. #1
    DarthZ is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    17

    Trouble with opening specific records using combo box


    Hello,

    The way my database is set up is that I have a form that acts as a guide. This form just has some buttons that open up the actual data-input forms. I wanted to add to this guide a combo- box with the list of records in one of the forms. All of the records have an ID number, so the combo-box is right now populated by those ID numbers. I want it so that when I click on a specific ID number it opens of the form containing the records that correspond to the selected ID.

    So far searching for solutions online, I tried using this vba code which seemed the most common "solution" : DoCmd.OpenForm "formname", , , "[ID]=" & Me![comboboxname]

    This code opens the form successfully, however the form is completely blank for some reason. Am I using the correct code? are there any better alternatives?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It is indicating the filter did not find any records. If your ID number is a string then you will need to change the WhereCondition argument to:
    DoCmd.OpenForm "formname", , , "[ID]= '" & Me![comboboxname] & "'"
    Or maybe the ComboBox is not bound to the correct column.

  3. #3
    DarthZ is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    17
    Thanks for the response,

    I tried your suggestion, however I keep getting the following error: data type mismatch in criteria expression

    I am still quite new to access, and so I am unfamiliar with what you meant when you said if my ID number is a string. The ID number we are using for this database will be 6-8 numerical digits

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    What is the FieldType of the field in the table where it resides; Text or Numerical?

  5. #5
    DarthZ is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    17
    it is numerical

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    What is the SQL for the RowSource of the ComboBox and which column of the RowSource is the bound column?

  7. #7
    DarthZ is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    17
    Here is the rowsource:

    SELECT [formname].[autonumber], [formname].[ID] FROM [formname];

    and it is bound to column 1

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    In that case your original:
    DoCmd.OpenForm "formname", , , "[ID]= " & Me![comboboxname]
    ...should work, as long as the ID is a current valid ID in the next form's RecordSource. Is it?

  9. #9
    DarthZ is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    17
    check that, not [formname] but [tablename] for rowsource

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You could put a:
    MsgBox "[" & Me.ComboBoxName & "]"
    ...just before opening the next form to see what value is being passed.

  11. #11
    DarthZ is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    17
    Okay, so I played around with the rowsource and I think I found a solution:

    I replaced the [Auto-number] in the rowsource with a [name] field I have in the table. I did this because I found on another forum that someone had the same error message involving a combo box and they found that the combo box was trying to store their auto-number into a text field.

    And so now that the auto-number field has been replaced with an actual text field, the mismatching error is no longer occurring, and the combo box is working as I had hoped it would.

    I used the DoCmd.OpenForm "formname", , , "[ID]= '" & Me![comboboxname] & "'" that you provided in the "after update" for the combo box.

    Thanks for your help RuralGuy, I really appreciate it

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Excellent! Glad we could help.

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

Similar Threads

  1. opening up form on specific part of the page
    By gbmarlysis in forum Forms
    Replies: 1
    Last Post: 02-29-2012, 05:06 PM
  2. Trouble with Combo Box
    By djclntn in forum Forms
    Replies: 16
    Last Post: 02-21-2012, 05:59 PM
  3. trouble opening switchboards
    By mejia.j88 in forum Programming
    Replies: 1
    Last Post: 01-13-2012, 04:15 AM
  4. Trouble opening Access file
    By nicknameoscar in forum Access
    Replies: 5
    Last Post: 08-08-2011, 12:32 PM
  5. Replies: 0
    Last Post: 05-18-2007, 02:49 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