Page 1 of 3 123 LastLast
Results 1 to 15 of 37
  1. #1
    Join Date
    Jul 2003
    Posts
    41

    Unanswered: using combo boxes as a parameter for a query

    I have created an unbound form, added a combo box and command button which will run the query. Then I have opened my query and built my expression, however, when I run execute the command button on the form I get no results. However when I run the query outside of the form I get results. I am trying to allow a user to make a selection from a combo box instead of typing in a value.
    Patricia Robey

  2. #2
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    if the query's criteria is based on the value of the combobox - more than likely it is using the valu of the bound column.

    The bound column (usually not visible to the user) is generally the ID for the text (description) column of the recordset

    ID MYDESC
    1 MYData1
    2 MyData2

    if the query is referencing the form as

    forms!myform!mycombobox it is probably getting the ID valu (1 or 2 in this case) and not the text values


    Just a guess based on what you posted.

  3. #3
    Join Date
    Jul 2003
    Posts
    41
    How do I change this?
    Patricia Robey

  4. #4
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    format tab on the property sheet of the combobox

    look for boundcolumn line change to column 2 - if in fact this is the problem

    Does this sound like it is?

    you can test this by placing the following code behind the afterupdate event of the combobox

    msgbox comboboxName (whatever the name of the combobox is)

    then select a different valu in form view and see what is displayed.

    If it is a numeric value it is probably the id

  5. #5
    Join Date
    Jul 2003
    Posts
    41
    I can now select a value from the combo box and get results. However if I try to select a different value I am not able to.
    Patricia Robey

  6. #6
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    results such as what and behind what events?

  7. #7
    Join Date
    Jul 2003
    Posts
    41
    I have a combo box that lists the different departments. What I am actuallywanting to do is produce a report from a query, however I want the user to be able to select a specific department. When I select the department and get the results, I am not able to select another department for that particular department. I am not sure what you are referring to when you speak of events.
    Patricia Robey

  8. #8
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    so you are saying that after selecting say "Dept1" and the query runs

    you cannot go back to the form and select another dept (Dept2) from the list and run the query?

    Keep the msgbox code (msgbox comboxname) behind the afterupdate event of the combobox and see what value is displayed after each selection

    if the value changes as you select different items then the problem may be in the query or how you call the query

  9. #9
    Join Date
    Jul 2003
    Posts
    41
    What is the best way to set up a combo box with value to can be selected when running a report? I may be doing it the wrong way?
    Patricia Robey

  10. #10
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    if the criteria for the report is based on a value from the combobox

    go to the report in design mode

    show the property sheet

    select the data tab
    go to recordsource

    click the 3 button (ellipse) to the right

    in the design grid of that query go to the column that represents the criteria that is needed from the combobox

    on the criteria line for that field (column) place the following

    forms!FormName!comboboxName

    where formName = the name of the form - If it is more than One word seperated by spaces place the name in Brackets
    [My Form name]

    same goes for the combobox name

  11. #11
    Join Date
    Jul 2003
    Posts
    41
    I tried this and when I ran my report it returned no records.
    Patricia Robey

  12. #12
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    you may be viewing the text value of that combo bos but it may be bound to the id field which 9 times out of ten will be a numeric value

    goto the design of the combobox and go to the data tab of property sheet
    change bound column from 1 to 2

    If this is all the box is for - it will not have any negative affect in the code

    then run the query

  13. #13
    Join Date
    Jul 2003
    Posts
    41
    This did not help. What I am trying to do is. I have created a query and am trying to run a report, however, I would like to select the values from a combo box whenever I run my report.

    Thanks for any help.
    Patricia Robey

  14. #14
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    I understand

    select a value from the combobox

    now hardcode that valu in the query

    any records?

    If so

    change the criteria in the query from the hard value to

    forms!formname!comboboxname
    select from the combobox the same value you used for the hardcoded criteria

    where formname is the name of the form
    comboboxname is the name of the combobox

    if no records - then the you are not referencing the name of the combobox or the bound coulmn for the combobox is not the same as that which is being displayed

  15. #15
    Join Date
    Jul 2003
    Posts
    41
    This is all new to me so please bear with me. What do you mean by hardcode?
    Patricia Robey

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •