Unable to set the Control Source Property in a report

rushwire

Registered User.
Local time
Yesterday, 19:22
Joined
Jul 13, 2010
Messages
11
In Access 2002 I am creating a new instance of a report object from a form using:

Dim rpt As New Report_rpt
Set rpt = New Report_rpt

I am then trying to set the GroupLevel ControlSource of the report in the Report_Open section using:

Me.GroupLevel(0).ControlSource = "Test"

and am getting the error message:

"You can't set the Control Source property in print preview or after printing has started"

I am only getting this error message if I open up the report as a new object. If I just open it as a standard report everything works OK. However I need multiple instances of the same report showing different gropuing levels. Has anyone any ideas?

Thanks in advance
James
 
This is a related thread
http://www.access-programmers.co.uk/forums/showthread.php?t=84179

Back in 2003 - this was also noted:
A: Use the On Open event of the report instead of the On Activate event
Q: Assigning the RecordSource via code prevents the Field list to be shown so how can I bind the various fields in the RecordSource result set to corresponding text boxes in the Detail section of the report?
A: Temporarily set the record source of the report to an appropriate query. When you have set the control sources, you can clear the record source.

For what it is worth in Access 2007:
A: I changed this from the on load property to on open property and it seems to work. Sorry, I guess I still didn't really understand the difference between the two.

My experience in Access reports is not all that great. Hope this helps.
 
You can set the grouping level just like you are doing in the Open Event (we do it here too) but your syntax is wrong. You need to use

Me.GroupLevel(0).ControlSource = "=[Test]"
 
Good one Bob! Of course. I had this same problem once, forgot all about it.
I spent about 15 minutes during lunch hour searching on this error. Didn't see this solution mentioned in a single internet post.
Hope RushWire gives you a well deserved Thanks!
 
Thank you both for your help. Unfortunatly though I am still getting the same error. It appears to be related to the fact that I am creating a new instance of the report object.

I have created a very simple test.

I have a form with a single button and the following code (g_bTest is declared as a global boolean variable in a seperate module:

Dim rpt1 As Report_temp
Dim rpt2 As Report_temp

Private Sub cmdClickMe_Click()

g_bTest = True
Set rpt1 = New Report_temp
rpt1.Visible = True

g_bTest = False
Set rpt2 = New Report_temp
rpt2.Visible = True

End Sub

I then have a report with the following code:

Private Sub Report_Open(Cancel As Integer)

If g_bTest = True Then
Me.GroupLevel(0).ControlSource = "=[ID1]"
Else
Me.GroupLevel(0).ControlSource = "=[ID2]"
End If

End Sub

If I run the report directly (i.e. just by double clicking it in the database window), it works fine (g_bTest is set to false be default). This is not what I want though as I require several instances of the same report. However if I click the button in the form I get the same error message as before:
"You can't set the Control Source property in print preview or after printing has started"

Thanks again for your help.

James
 
Why are you trying to create a new instance of the report instead of using the report itself?
 
because the client requires the same report to be shown multiple times but with different groupings.
 

Users who are viewing this thread

Back
Top Bottom