How to set ControlSource property of a textbox in a subreport at runtime

  • Thread starter Thread starter Yuko Joslin
  • Start date Start date
Y

Yuko Joslin

I would like to set ControlSource property of a textbox in a subreport at
runtime . When I tried to set ControlSource in Report_Open event procesure of
sub report, I received "2191" error - you cannot set the control source
property in print preview or after printing has started. Where and when could
I set this property ?
 
Yuko said:
I would like to set ControlSource property of a textbox in a subreport at
runtime . When I tried to set ControlSource in Report_Open event procesure of
sub report, I received "2191" error - you cannot set the control source
property in print preview or after printing has started. Where and when could
I set this property ?


You can do it in the subreport's Open event, but only the
first time it's called. A simple check can be coded for
this situation"

Private Sub Report_Open(
Static Initialized As Boolean
If Not Initialized Then
Me.textbox.ControlSource = whatever
Initialized = True
End If
End Sub
 
Hi Marshall,
It worked perfect ! My actual coding includes lines of calculation and
assignment to multiple textboxes, but your method worked. Thank you so much.
Another problem...I would like to set filter to the underlying recordset for
the subreport, and put the following statements just before "Initialized =
True" Statement as shown below - then I received the error 2101- "The
setting you entered isn't valid for this property". It worked when I open the
subreport itself, but it failed when it was executed as "subreport in main
report. The filter should be set justr before this sub report will be
generated. Any suggestions?

Private Sub Report_Open(
Static Initialized As Boolean
If Not Initialized Then
Me.textbox.ControlSource = <Source>
Me.Filter = <Filter>
Me.FilterOn = True
Initialized = True
End If
End Sub
 
Yuko said:
Hi Marshall,
It worked perfect ! My actual coding includes lines of calculation and
assignment to multiple textboxes, but your method worked. Thank you so much.
Another problem...I would like to set filter to the underlying recordset for
the subreport, and put the following statements just before "Initialized =
True" Statement as shown below - then I received the error 2101- "The
setting you entered isn't valid for this property". It worked when I open the
subreport itself, but it failed when it was executed as "subreport in main
report. The filter should be set justr before this sub report will be
generated. Any suggestions?

Private Sub Report_Open(
Static Initialized As Boolean
If Not Initialized Then
Me.textbox.ControlSource = <Source>
Me.Filter = <Filter>
Me.FilterOn = True
Initialized = True
End If
End Sub
 
Yuko said:
Hi Marshall,
It worked perfect ! My actual coding includes lines of calculation and
assignment to multiple textboxes, but your method worked. Thank you so much.
Another problem...I would like to set filter to the underlying recordset for
the subreport, and put the following statements just before "Initialized =
True" Statement as shown below - then I received the error 2101- "The
setting you entered isn't valid for this property". It worked when I open the
subreport itself, but it failed when it was executed as "subreport in main
report. The filter should be set justr before this sub report will be
generated. Any suggestions?

Private Sub Report_Open(
Static Initialized As Boolean
If Not Initialized Then
Me.textbox.ControlSource = <Source>
Me.Filter = <Filter>
Me.FilterOn = True
Initialized = True
End If
End Sub


I don't use the Filter property. so I can't speak to it's
problems in this situation. (I prefer to set the
subreport's RecordSource property instead.)

If you'll post what you used for <Filter>, maybe I can check
if you have used something that only works for main reports.
Please use Copy/Paste so I can see exactly what your code
looks like.
 
After searching for the similar problems in this Forum and read the article
in Allen Browne's Site,
(http://allenbrowne.com/bug-02.html) I have learned that using filter in
subreport cound fail - a flaw of Access...So, I decided to use RecordSource
property instead. It worked! Thank you so much!
Private Sub Report_Open(
Static Initialized As Boolean
If Not Initialized Then
Me.textbox.ControlSource = <Source>
Me.RecordSource = <SQL strings>
Initialized = True
End If
End Sub



Yuko said:
Hi Marshall,
It worked perfect ! My actual coding includes lines of calculation and
assignment to multiple textboxes, but your method worked. Thank you so much.
Another problem...I would like to set filter to the underlying recordset for
the subreport, and put the following statements just before "Initialized =
True" Statement as shown below - then I received the error 2101- "The
setting you entered isn't valid for this property". It worked when I open the
subreport itself, but it failed when it was executed as "subreport in main
report. The filter should be set justr before this sub report will be
generated. Any suggestions?

Private Sub Report_Open(
Static Initialized As Boolean
If Not Initialized Then
Me.textbox.ControlSource = <Source>
Me.Filter = <Filter>
Me.FilterOn = True
Initialized = True
End If
End Sub
[quoted text clipped - 13 lines]
End If
End Sub
 
Hi Marshall,

I am sorry, but I did not notice your reply. As I posted the former reply, I
used RecourdSource
property, and It worked. <Filter> portion works with subreport when it is
executed as report,
but it did not work for main reports. Thank you, Marshall.

Marshall said:
Hi Marshall,
It worked perfect ! My actual coding includes lines of calculation and
[quoted text clipped - 16 lines]
End If
End Sub

I don't use the Filter property. so I can't speak to it's
problems in this situation. (I prefer to set the
subreport's RecordSource property instead.)

If you'll post what you used for <Filter>, maybe I can check
if you have used something that only works for main reports.
Please use Copy/Paste so I can see exactly what your code
looks like.
 
Back
Top