Help! Set control source of subreport fields dynamically on load

T

Tirelle

I have created a report which I need to set the control source of a group
of fields on the subreport dynamically when opened. The goal is only to put
string in the fields in all fileds named week1,week2,etc. at the code level
so that if I add controls they will inherit this controlsource. Here is the
code :

Private Sub Report_Load()
Dim WkOf As Control
For Each WkOf In Me.sbrptQualifications.Controls
If Left(WkOf.Name, 4) = "Week" Then
'WkOf.ControlSource = "
=IIf([LastWeekGenerated]>=1,getweekof([startdate],[lastweekgenerated],1),"""")"
Reports!rptQualificationSequence!sbrptQualifications(WkOf.Name).ControlSource
= "
=IIf([LastWeekGenerated]>=1,getweekof([startdate],[lastweekgenerated],1),"""")"
End If
Next
End Sub

I currently have it in the main reports load event but I will put it
whereever needed to make it work. When I run it, I get a syntax error. Can
anyone help?
 

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