Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo box with report below?

Status
Not open for further replies.

mdmarney

IS-IT--Management
Jan 16, 2003
68
0
0
US
I need a combo box that people can select a group of reports from. I no not want to create a report for each group and then a combo linked to them. I would like the combo to automatically generate the printable report based on the selection in the box. How do I do this? *************
M. MARNEY
 
Combo boxes don't have multi select options. If you want to be able to select a group of reports then you will need to use a Listbox. This code will get you started.

Dim ctl As Control
Dim varItem as Variant
Set ctl = Forms!FormName!ListboxName
For Each varItem in ctl.ItemsSelected
DoCmd.OpenReport ctl.ItemDate(varItem),acViewPreview
Next varItem

Set ctl = Nothing

You will have to put your Report Names in a Table and then set the Listbox RowSource to that table. Once you get the listbox set up, put a Command Button on your form and put the above code in the Click Event for the Button. You will need to put your Form name and Listbox name where the BOLD is.

Paul
 
Maybe I didn't explain it well...

Say I have a table (tbl_people) and report(rpt_people_by_group) based off that table. The table (tbl_people) has a Group_ID field and the table is related to tbl_groups [many to one]. I would like to select a Group_ID and only generate the report for records in tbl_people where the Group_ID has been selected.
It is basically like a form/subform with a combo box that does a record lookup, but I do not know how to do it in a report. I could have a form with a combo for selection and then carry that value accross to a parameter query that supplies the data for the report? I don't know how to do that or if there is a better way... *************
M. MARNEY
 
Either way is good. Assuming you have a button to put either code behind, they would look like this. First the report from the combo without the query.

Dim myVal as String
myVal = Me.ComboBoxName
Docmd.OpenReport "rpt_people_by_group",acViewPreview,,"Group_ID = '" & myVal & "'"

To use the query, you would put the following on the Criteria line for your Group_ID
=Forms!FormName!ComboboxName

And then in the click event for the button it would just be
DoCmd.OpenReport "rpt_people_by_group", acViewPreview


Paul
 
Thank you Paul. I'll give it a try.
BTW, do you do independent work or support? I appeciate the help, but don't want to abuse your help. My work is for a non-profit, and I'm just a volunteer, so I apologize for the ignorance in my questions... *************
M. MARNEY
 
If things get more involved then Yes I do indepenant/support work. If it can be solved within the scope of this forum then that works for everyone.
Paul
 
The ID field is a LONG (longint)

I have:
Dim Group_Select As Long
Group_Select = Me.cbx_Group_ID_Selector
Debug.Print Group_Select
DoCmd.OpenReport "rpt_Shirt_Distribution_by_Group", acViewPreview, , "Parish_Group_ID = '" & Group_Select & "'"

BUT, I think the syntax around Group_Select is wrong.
Help??? *************
M. MARNEY
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top