Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change the value of a text box programtically

Status
Not open for further replies.

dixxy

Technical User
Mar 4, 2003
220
0
0
CA
Hello,

I have a report that I would like to manipulate a few textboxes with code. Reason being is that I would like this report to check if a customer is exempt of one or two taxes and calculate based on that..

Here is the code I am working with;
Code:
If Forms![frmjobs]!Name1.Column(10) = 3 Then
Me.txtPST.Value = 0
End If
I have this in the on format event of the report_footer, and those textboxes are unbound.

I always get a 'You can't asign a value to this object' error

Thanks,

Sylvain
 
sorry...same thing..

Thanks,

Sylvain
 
One thing I've overlooked in the past: You might want to verify that txtPST is a textbox and not a label control. I know you can get that error when trying to assign a value to a label....

Hoc nomen meum verum non est.
 
no it's a textbox alright...:-(


Thanks,

Sylvain
 
Please confirm "those textboxes are unbound". THis is a typical error message if the control source of the text box is not empty.

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
The other thing to consider: Is txtPST a calculated control?? You may want to assign the calculation as part of an If..Then..Else statement, or possibly an IIf statement.

Hoc nomen meum verum non est.
 
Duane,

u are right....the control source is bound to an expression...that's why it's not working...i thought it would only do this if it was bound to a field in a table or query....

Thanks,

Sylvain
 
Put this in the source control of the text box called txtPST.

Code:
=IIf([Forms]![frmjobs]!Name1.Column(10) = 3,"Value if True","Value if False")
 
I had the same problem just yesterday. Put the code in the Report_Activate() event. Make sure there is nothing attached to the on_open event otherwise anything that is assigned using code will return the error message you were getting. If you must use an On_Open event you have to open the report in design mode first then preview mode inorder to get around the error.

Good luck

-Mike
 
mck144,
In the original post, the issue was that the control was initially bound to an expression. It makes no difference where you attempt to set the value of a control if it is bound since it will always fail.

The event you call the code from may be dependent on the section containing the control. The OP's control was in the report footer which could be referenced in the On Open event. I haven't done much testing on this but would be interested in knowing where your control is located.

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
I thought they were unbound. My mistake.

The form I was referring to has all unbound text boxes. I used an ADODB recordset to return values to pass to various functions that do the calculations. These functions then return values to be assigned to the unbound text boxes. If I used this code in the On_Open() event and attempted to open the report outright I would get the 'You can't asign a value to this object' error. If I opened the report in design mode first then in preview mode the report ran with no errors. I moved the code to the Report_Activate() event and the report runs fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top