I am trying to set the Control Source of a particular field of a report as the report is opening. I suspect that there is a way to do it as part of the DoCmd.OpenReport argument, but can't find any syntax examples.
The report is printed from a set of Command Buttons on a form, each of which will print the same report, with the 'Barcode' field on the Report having it's Control Source set to Barcodex, depending on which Command Button calls the report. There are 10 Barcode fields on the form, and it would be sloppy to replicate the report 10 times. The code also picks up the current record from the 'ID' field.
I have tried setting the Control Source in a separate line of code, but get errors because the report is either not open or has already opened (see below). This report will eventually print directly to a label printer (it is only temporarily set to acPrintPreview), so I'm hesitant to try opening the report hidden, then setting the control source and refreshing it, because I'm thinking that this may cause unwanted labels to be spit out.
Here is the code:
- - -
Private Sub cmdPrintBarcode1_Click()
Dim strReportName As String
Dim varCriteria As Variant
strReportName = "rptPrintLabel"
'Set variable to pick current record
varCriteria = "[ID]=" & Me![ID] & ""
'Next line causes 'Report not open error'
Reports!rptPrintLabel!Barcode.ControlSource = Barcode1
DoCmd.OpenReport strReportName, acViewPreview, , varCriteria
'Next line causes 'Can't change after report open error'
Reports!rptPrintLabel!Barcode.ControlSource = Barcode1
End Sub
- - -
Using Access 2000
Thanks! - - - -
Bryan
The report is printed from a set of Command Buttons on a form, each of which will print the same report, with the 'Barcode' field on the Report having it's Control Source set to Barcodex, depending on which Command Button calls the report. There are 10 Barcode fields on the form, and it would be sloppy to replicate the report 10 times. The code also picks up the current record from the 'ID' field.
I have tried setting the Control Source in a separate line of code, but get errors because the report is either not open or has already opened (see below). This report will eventually print directly to a label printer (it is only temporarily set to acPrintPreview), so I'm hesitant to try opening the report hidden, then setting the control source and refreshing it, because I'm thinking that this may cause unwanted labels to be spit out.
Here is the code:
- - -
Private Sub cmdPrintBarcode1_Click()
Dim strReportName As String
Dim varCriteria As Variant
strReportName = "rptPrintLabel"
'Set variable to pick current record
varCriteria = "[ID]=" & Me![ID] & ""
'Next line causes 'Report not open error'
Reports!rptPrintLabel!Barcode.ControlSource = Barcode1
DoCmd.OpenReport strReportName, acViewPreview, , varCriteria
'Next line causes 'Can't change after report open error'
Reports!rptPrintLabel!Barcode.ControlSource = Barcode1
End Sub
- - -
Using Access 2000
Thanks! - - - -
Bryan