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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically assign name of Data Report

Status
Not open for further replies.

alanf

Programmer
Feb 7, 2001
39
US
Does anyone know if there is a way to dynamically assign the name of a data report at runtime. I want to have a generic procedure to populate multiple reports at run time. But when I try to dynamically assign the name of the report I get errors.

Set rptReport = sReportName gives me an "Object required" error message.
The Report.Name property is not settable at runtime.

Has anyone done this???
 
Hi

Where are you trying to do this?

If what you mean is to run one of several reports from a button, where (say) the report name is selected from a combo box, then in the onclick event of the button which runs the report:

Private Sub Print_C1_Click()
On Error GoTo Err_Print_C1_Click

Dim stDocName As String

stDocName = cboReportName
DoCmd.OpenReport stDocName, acNormal

Exit_Print_C1_Click:
Exit Sub

Err_Print_C1_Click:
MsgBox Err.description
Resume Exit_Print_C1_Click

End Sub

Wheer cboReportName is the name of the combo box used to select the report to run.

Hope this what you are trying to do. Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
kenneth.reaySPAMNOT@talk21.com
remove SPAMNOT to use
 
That's exactly what I'm trying to do, but in a VB/SQL Server app, not Access. I wanted to be able to generate multiple reports from a single routine, instead of having to write a unique routine for every report. I have figured out a workaround, but it still does not allow me to pull the name of the report from the database, and pass it to a routine to generate the report. I have to have the report names hard-coded in my generic routine.

What I have done is, to create a dummy report called "rptReport". (I had to create this dummy report, otherwise the .Hide and .Show methods were throwing errors!)Then in my routine, I have a Select Case statement:

Set rptReport = rptCustomerList

This works with "rptCustomerList" hard-coded. But if I pass the name "rptCustomerList" to the routine, for example

sReportName = "rptCustomerList"

Then the
Set rptReport = sReportName
generates the "Object required" error.

Any ideas?
 
Try using the same logic as with any other object, such as the below example does with a form:

Private Sub mnuForm1_Click()
Dim frm As New Form1
DoSomethingWithForm frm
End Sub

Proceedure in a class or public module:

Sub DoSomethingWithForm(f As Form)

f.Show

End Sub [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Thanks for your input CClint. The problem is, I want to take an existing report, pull it's name from the database, and get a handle to it. No matter what I try, I can't get a handle to it, using its name in a variable.

So if the reportname is passed from the db to a variable, say sReportName, so sReportName = "rptCustomers", then the code:

Dim rpt As New sReportName

causes an error "User-defined type not defined"

If I try,

Dim rpt As Object

Set rpt = sReportName

I get a type mismatch.

The problem is getting a string, the name of the report, to become a reference to the object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top