Using a string variable to reference a report object

  • Thread starter AaronWestcott via AccessMonster.com
  • Start date
A

AaronWestcott via AccessMonster.com

I am trying to use a

with Reports!"Report name"
.property
end with

though I would like "report name" to be string variable.

Is this possible and if so how would one go about doing this?

Thanks.
 
D

Douglas J. Steele

Dim strReportName As String

strReportName = "Report Name"
With Reports(strReportName)

End With
 
B

Bernie

Douglas J. Steele said:
Dim strReportName As String

strReportName = "Report Name"
With Reports(strReportName)

End With

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)





Private Sub Trip_Sheet_Click()

If Forms!frmTripheader!tabTripHeaderID <> "" Then
Call Fuel_Click
rep = "Trip Sheet"
repname = "repTripSheet"
repquery = strSQL
reptitle = "Trip Sheet"
Call OpenReport(rep, repquery, reptitle, repname)
Else
MsgBox ("Please chose trip"), vbInformation, "Trip Sheet"

End If

End Sub


then you need this routine:

Public Function OpenReport(rep, repquery, reptitle, repname)

DoCmd.OpenReport repname, acDesign
Reports(repname).RecordSource = repquery
'Reports(repname)!Title.Caption = reptitle
DoCmd.Close acReport, (repname), acSaveYes
DoCmd.OpenReport (repname), acPreview

End Function

Main advantage:

Routine passes on datasource, report title etc.
 

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