Opening a Report based on combobox selection (1 Viewer)

tgonzalez

New member
Local time
Today, 16:49
Joined
Sep 25, 2013
Messages
2
Hey everyone,

I am trying to run a report based on a combobox selection. I have three different reports, each for the three different items in the combo box. I just don't know how to code it so when I run the report, it picks up the name in the combo box and opens the correct report. This is what my code looks like for the button that will run the report:

Private Sub Command7_Click()
DoCmd.OpenReport ("Signers Authorized for Check Writing"), acViewPreview, , WhereCondition = [BTrans] = "Check Writing"
DoCmd.OpenReport ("Signers Authorized for Stop Payment"), acViewPreview, , WhereCondition = [BTrans] = "Stop Payments"
DoCmd.OpenReport ("Signers Authorized for Wires"), acViewPreview, , WhereCondition = [BTrans] = "Wires"
End Sub

The problem is, that as soon as I hit the Run Report button, all three reports open up, so it is not reading what is in the combo box. The quotes, "Check Writing" , "Stop Payments" and "Wires" are the actual selections in the combobox and [BTrans] is the name of the combobox.

Any help would be awesome!!!!

:)
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 10:49
Joined
Jan 20, 2009
Messages
12,849
Assuming the BoundColumn of the combo holds the name of the reports.
Code:
DoCmd.OpenReport Forms!formname.comboname, acViewPreview, , "[BTrans]='Check Writing'"

Note the syntax of the Where argument, particularly the single quotes.
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 10:49
Joined
Jan 20, 2009
Messages
12,849
BTW Assuming "Check Writing" is one of a number of fixed possible values it is a better practice to store this information as numeric values in the table.

A lookup table is used to store the text represented by the numbers just once. It is considerably more efficient to store and search the number rather than the text.
 

tgonzalez

New member
Local time
Today, 16:49
Joined
Sep 25, 2013
Messages
2
Thank you for answer. I still don't see how that will open up a specific report. There are three reports. One for each of the selections on the combo box. I think that code is to open a report based on a form??
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 10:49
Joined
Jan 20, 2009
Messages
12,849
The first argument of the OpenReport Method is a string that defines the name of the report to be opened. If the combo has the name of the report then that is what will be opened.
 

Users who are viewing this thread

Top Bottom