change value of unbound textbox after report opens

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can you use VB to change the value of a textbox that has no control source
after the report has been opened?
e.g. TestTextBox.Value = "Andrew" where TestTextBox is the name of an
unbound textbox in the report

When I try this code, the text box doesn't change. Do I have to refresh the
report in some way?

Know this is a simple query but can't get it to work!
 
Yes, that is possible. It is a matter of when you want to do it and what
section the text box is in. The syntax is standard VBA:
Me.TestTextBox = "Andrew"

This is not atypical. There are times when you don't know what the value
for the text box will be until you open the report. In this case, you would
do it in the Open event of the report.
 
Yes, that is possible. It is a matter of when you want to do it and what
section the text box is in. The syntax is standard VBA:
Me.TestTextBox = "Andrew"

This is not atypical. There are times when you don't know what the value
for the text box will be until you open the report. In this case, you would
do it in the Open event of the report.

Klatuu,

Not in the Report's Open event.
That's too early in the Report formatting.

But if use the Report's Report Header format event or any later
occurring event, Yes.
 
Oh, really? The how does this code from one of my production reports work,
then?

Private Sub Report_Open(Cancel As Integer)

On Error GoTo Report_Open_Error

'Activity is always last
Me.GroupLevel(5).ControlSource = "Activity"
With Forms!frmUPOreports
'Determine which Subtotals have been selected
'HomeRooom
If .chkHomeRoom Then
Me.GroupLevel(4).ControlSource = "PerformAcctUnit"
Else
Me.GroupLevel(4).ControlSource = Me.GroupLevel(5).ControlSource
End If
'Pool
If .chkPool Then
Me.GroupLevel(3).ControlSource = "Pool"
Else
Me.GroupLevel(3).ControlSource = Me.GroupLevel(4).ControlSource
End If
'BillNetwork
If .chkBillNetwork Then
Me.GroupLevel(2).ControlSource = "BillNetwork"
Else
Me.GroupLevel(2).ControlSource = Me.GroupLevel(3).ControlSource
End If
'MasterActivity
If .chkMActivity Then
Me.GroupLevel(1).ControlSource = "MActivity"
Else
Me.GroupLevel(1).ControlSource = Me.GroupLevel(2).ControlSource
End If
End With
'Top Level For Billable Product Offering
Me.GroupLevel(0).ControlSource = "ProjectId"
 
Oh, really? The how does this code from one of my production reports work,
then?

Private Sub Report_Open(Cancel As Integer)

On Error GoTo Report_Open_Error

'Activity is always last
Me.GroupLevel(5).ControlSource = "Activity"
With Forms!frmUPOreports
'Determine which Subtotals have been selected
'HomeRooom
If .chkHomeRoom Then
Me.GroupLevel(4).ControlSource = "PerformAcctUnit"
Else
Me.GroupLevel(4).ControlSource = Me.GroupLevel(5).ControlSource
End If
'Pool
If .chkPool Then
Me.GroupLevel(3).ControlSource = "Pool"
Else
Me.GroupLevel(3).ControlSource = Me.GroupLevel(4).ControlSource
End If
'BillNetwork
If .chkBillNetwork Then
Me.GroupLevel(2).ControlSource = "BillNetwork"
Else
Me.GroupLevel(2).ControlSource = Me.GroupLevel(3).ControlSource
End If
'MasterActivity
If .chkMActivity Then
Me.GroupLevel(1).ControlSource = "MActivity"
Else
Me.GroupLevel(1).ControlSource = Me.GroupLevel(2).ControlSource
End If
End With
'Top Level For Billable Product Offering
Me.GroupLevel(0).ControlSource = "ProjectId"

Regarding your >(Me.GroupLevel(5).ControlSource = "Activity").<

You're setting the Control Source to a particular Field, the
[Activity] field, not to a particular value in that field.

Let's make a test.
Add an unbound text control to the report (in the Header or Page
Header or Detail section, whatever).
Let's name the control "TestTextBox"

Code the Report's Open event to what the OP wanted to display
"Andrew".
Me![TestTextBox] = "Andrew" (as per your original reply to the OP.)

Run the report. It should generate Error 2448 "You can't assign a
value to this object"

Now change the Open event code to:
Me![TestTextBox].ControlSource = "Activity" or whatever field contains
the value "Andrew". In my test Db it would be [FirstName].

Run the report and you will get what ever the value of the [Activity]
field is, but not the word "Activity". The OP asked to have the
specific value "Andrew" displayed, (TestTextBox.Value = "Andrew") not
the value of a particular field.

Now if you move the code Me![TestTextBox] ="Andrew" from the Report's
Open event to the Report's Report Header Format event, it works just
fine. The report displays the word "Andrew".
 
In the Report Open Event
This did not work:
Me.Text39 = "Andrew"
This did work:
Me.Text39.Caption = "Andrew"


fredg said:
Oh, really? The how does this code from one of my production reports work,
then?

Private Sub Report_Open(Cancel As Integer)

On Error GoTo Report_Open_Error

'Activity is always last
Me.GroupLevel(5).ControlSource = "Activity"
With Forms!frmUPOreports
'Determine which Subtotals have been selected
'HomeRooom
If .chkHomeRoom Then
Me.GroupLevel(4).ControlSource = "PerformAcctUnit"
Else
Me.GroupLevel(4).ControlSource = Me.GroupLevel(5).ControlSource
End If
'Pool
If .chkPool Then
Me.GroupLevel(3).ControlSource = "Pool"
Else
Me.GroupLevel(3).ControlSource = Me.GroupLevel(4).ControlSource
End If
'BillNetwork
If .chkBillNetwork Then
Me.GroupLevel(2).ControlSource = "BillNetwork"
Else
Me.GroupLevel(2).ControlSource = Me.GroupLevel(3).ControlSource
End If
'MasterActivity
If .chkMActivity Then
Me.GroupLevel(1).ControlSource = "MActivity"
Else
Me.GroupLevel(1).ControlSource = Me.GroupLevel(2).ControlSource
End If
End With
'Top Level For Billable Product Offering
Me.GroupLevel(0).ControlSource = "ProjectId"

Regarding your >(Me.GroupLevel(5).ControlSource = "Activity").<

You're setting the Control Source to a particular Field, the
[Activity] field, not to a particular value in that field.

Let's make a test.
Add an unbound text control to the report (in the Header or Page
Header or Detail section, whatever).
Let's name the control "TestTextBox"

Code the Report's Open event to what the OP wanted to display
"Andrew".
Me![TestTextBox] = "Andrew" (as per your original reply to the OP.)

Run the report. It should generate Error 2448 "You can't assign a
value to this object"

Now change the Open event code to:
Me![TestTextBox].ControlSource = "Activity" or whatever field contains
the value "Andrew". In my test Db it would be [FirstName].

Run the report and you will get what ever the value of the [Activity]
field is, but not the word "Activity". The OP asked to have the
specific value "Andrew" displayed, (TestTextBox.Value = "Andrew") not
the value of a particular field.

Now if you move the code Me![TestTextBox] ="Andrew" from the Report's
Open event to the Report's Report Header Format event, it works just
fine. The report displays the word "Andrew".
 
Back
Top