Running a report with specific data from a combo box

G

Guest

Is there anyway to run a report to show information on specific data that is
found in a combo box? For example, on my query I have a combo box with a
list of names. I want to be able to run a report by specifing a certain name
in the drop down box. I know that on the query related to the report I can
place a [enter name] in the criteria field but is there anyway to have
someone choose an option instead of having to type it in.
 
G

Guest

Hi KRDitch,
You may create a table with 2 fields (E.g: RptName; Description). Type the
name of the Reports to RptName Field (exactly !), then set the Row Source of
the Combo Box to the table. Set Column Count to 2, Colum Width to 0";2" ...
Here is the sample code in the After Update event of the Combo Box:
(You may have to change the Combo Box's name)
---------------
Private Sub Combo1_AfterUpdate()
Dim stDocName As String
stDocName = Combo1.Column(0)
DoCmd.OpenReport stDocName, acPreview
End Sub
 
S

SA

There are two really easy ways to do this:

First add a combo to a form that will call your report and populate it with
the list of names, and a button to open the report

Then either:

1.) In the query that sits behind the report, in the condition row for the
field with the names it add a condition like:

Forms!YourFormName!YourComboName

and Select an event procedure in the On Click event of the button.

Add code like this to the button

If Not IsNull(Me!YourComboName) Then
Docmd.OpenReport "YourReportName"
Else
MsgBox "Select a Name from the List",16
End if

2.) if you don't want to always have that report tied to this particular
form (which it would be if you add the condition to the query as in #1
above,) Don't change the report's query and add code like this to the
button's event procedure:

If Not IsNull(Me!YourComboName) Then
Docmd.OpenReport "YourReportName", acViewNormal, , "[YourNameFieldsName]
= '" & Me!YourComboName & "'"
'that's apostrophe, quotation, ampersand, comboname, quotation,
apostrophe, quotation
Else
MsgBox "Select a Name from the List",16
End if
 
G

Guest

Ok - So I don't know if my brain is having a moment or what but....

I attempted to use the first example that you gave me and on the form that I
have there is a print button on the report that has a macro associated with
it to print the report out that I need. When the button is pushed now it is
asking for general information such and the date and the person's ID number
so only certain things print for that person. This information I have in a
query that is associated with that report. Where exactly am I adding the
code?

SA said:
There are two really easy ways to do this:

First add a combo to a form that will call your report and populate it with
the list of names, and a button to open the report

Then either:

1.) In the query that sits behind the report, in the condition row for the
field with the names it add a condition like:

Forms!YourFormName!YourComboName

and Select an event procedure in the On Click event of the button.

Add code like this to the button

If Not IsNull(Me!YourComboName) Then
Docmd.OpenReport "YourReportName"
Else
MsgBox "Select a Name from the List",16
End if

2.) if you don't want to always have that report tied to this particular
form (which it would be if you add the condition to the query as in #1
above,) Don't change the report's query and add code like this to the
button's event procedure:

If Not IsNull(Me!YourComboName) Then
Docmd.OpenReport "YourReportName", acViewNormal, , "[YourNameFieldsName]
= '" & Me!YourComboName & "'"
'that's apostrophe, quotation, ampersand, comboname, quotation,
apostrophe, quotation
Else
MsgBox "Select a Name from the List",16
End if
--
SA
ACG Soft
http://www.groupacg.com



KRDitch said:
Is there anyway to run a report to show information on specific data that
is
found in a combo box? For example, on my query I have a combo box with a
list of names. I want to be able to run a report by specifing a certain
name
in the drop down box. I know that on the query related to the report I
can
place a [enter name] in the criteria field but is there anyway to have
someone choose an option instead of having to type it in.
 
G

Guest

Here is the code that is currently associated with the button that I have for
pulling the report -

Private Sub Reroutes_Not_Rec_Back_Report_Print_Button_Click()
On Error GoTo Err_Reroutes_Not_Rec_Back_Report_Print_Button_Click

Dim stDocName As String

stDocName = "Reroutes Not Received Back Report"
DoCmd.OpenReport stDocName, acNormal

Exit_Reroutes_Not_Rec_Back_Report_Print_:
Exit Sub

Err_Reroutes_Not_Rec_Back_Report_Print_Button_Click:
MsgBox Err.Description
Resume Exit_Reroutes_Not_Rec_Back_Report_Print_

End Sub

Not quite sure where to add code asking to chose an item from the drop down
box in order to run the report.

SA said:
There are two really easy ways to do this:

First add a combo to a form that will call your report and populate it with
the list of names, and a button to open the report

Then either:

1.) In the query that sits behind the report, in the condition row for the
field with the names it add a condition like:

Forms!YourFormName!YourComboName

and Select an event procedure in the On Click event of the button.

Add code like this to the button

If Not IsNull(Me!YourComboName) Then
Docmd.OpenReport "YourReportName"
Else
MsgBox "Select a Name from the List",16
End if

2.) if you don't want to always have that report tied to this particular
form (which it would be if you add the condition to the query as in #1
above,) Don't change the report's query and add code like this to the
button's event procedure:

If Not IsNull(Me!YourComboName) Then
Docmd.OpenReport "YourReportName", acViewNormal, , "[YourNameFieldsName]
= '" & Me!YourComboName & "'"
'that's apostrophe, quotation, ampersand, comboname, quotation,
apostrophe, quotation
Else
MsgBox "Select a Name from the List",16
End if
--
SA
ACG Soft
http://www.groupacg.com



KRDitch said:
Is there anyway to run a report to show information on specific data that
is
found in a combo box? For example, on my query I have a combo box with a
list of names. I want to be able to run a report by specifing a certain
name
in the drop down box. I know that on the query related to the report I
can
place a [enter name] in the criteria field but is there anyway to have
someone choose an option instead of having to type it in.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top