3071 Error when report name is a variable

E

ElPresidente

Hi everyone,

I have several reports which are accessed through a form that allows
the user to specify a date range. The form also allows the user to
either view the report, print the report, or export it to PDF. Since
all the reports would have the identical form, I thought it would be
best to have one form, and have the "Run Report" button pull up the
correct report based on the one that was selected from the
switchboard. So I wrote the following code:

If (reportOptions = 1) Then
DoCmd.OpenReport reportName, acViewPreview, "", "", acNormal
End If

I'm still new to VBA so maybe I'm not writing this expression
correctly. The variable is a string name such as mthlyCustomers. If I
replace reportName with "mthlyCustomers" the report opens. What is the
workaround for this or do I have to create several identical forms?
 
K

Klatuu

Where is reportName Dimmed?
Where is it populated with the name of the report you want to open?
There is nothing really wrong with your code except you don't need to put
the "" in the empty arguements, just leave them blank:

If reportOptions = 1 Then
DoCmd.OpenReport reportName, acViewPreview, , , acNormal
End If
 
E

ElPresidente

Thanks for replying.

I'm still new to VBA, but I knew that the code should be working.
Turns out there is a problem with a couple of the reports themselves
when I converted to VBA from macros.
 

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