"You Can't Assign a Value to This Object"

jastek

Registered User.
Local time
Today, 22:25
Joined
Aug 8, 2003
Messages
29
I am trying to set the Control Source for a textbox = to a function in a global module that contains an elseif calculation. When I open the form, I get the error "You Can't Assign a Value to This Object".

Anyone know why I get the error?

Attached is a very simple database to illustrate what I am trying to do:
 

Attachments

Last edited:
You must be using Access 2003. I can't open it with 2K and that may be the case for many members here.
 
It's an A2002 file. The problem is that you can't assign a value to a control where it has an expression for a ControlSource.
 
So, how do I have this control's value calculated using the function?

If I call this function from an event, such as the forms On Open event, it works.

I want the calculation to be performed continuously on every record, without depending on an event to occur, since the calculation will change everyday.
 
So, how do I have this control's value calculated using the function?

You can't. Not directly. A bound textbox wants an underlying record. You could make an UNBOUND text box that has a value originating from a form's OnCurrent event.

I want the calculation to be performed continuously on every record, without depending on an event to occur, since the calculation will change everyday.

If you meant that literally as it reads, you can't. But we could have a nomenclature problem. One of these two cases might apply.

a. You want the value in the form's textbox to change when someone else sharing this database updates something that affects the value... NO, you need an event to trigger code. You MIGHT be able to do this, say, every minute using an OnTimer event. Don't forget, you are in a Windows box. You might not realize this, but trust me. NOTHING occurs in Windows without an event somewhere, even if it is only a timer event. It is not only Access that has this problem, but every program suitable for use with good ol' Windows, too!

b. You want the value in the form's textbox to be reevaluated every time you change underlying records on the form. YES, use the OnCurrent event to recompute the value for the unbound text box.

When I open the form, I get the error "You Can't Assign a Value to This Object".

Anyone know why I get the error?

Yeah, Access doesn't have an underlying recordset as the recordsource for the box so any changes to its contents cannot be recorded anywhere. Well, when you compute a conditional result to change the contents of the TextBox, Access wants to write that result in the recordset - but there isn't one! Instead, you get what APPEARS to be a recursive call to the very same function that wanted to update the text box in the first place. Access detects this implied recursion and runs screamin' like a banshee.
 
Doc_Man - Thanks for the info. I will aproach this from another direction.

Just one more question. How do you make all records update at the same time? I want all of the records to recalculate before I run a report, so the information is up to date. When I call the function that recalculates the information, only the current record gets updated.
 
Just do the calculation in a query - it should, therefore, always be accurate at runtime. You should not be storing calculated values in your table.
 
I will create an update query and run it at startup.


Why should I not be storing values in my table?
 
You shouldn't store calculated values in your table as it is against the Third Normal Form (3NF) of database design which states that you should not have non-key dependencies in your table. A non-key dependency is one field that relies on one or more fields that are not the primary key of the table. An example would be three fields called Quantity, Price, and Total. Obviously the Total will be the Quantity multiplied by the Price. So, should the information be changed accidentally in either the Quantity or Price fields then the calculated value that is the Total will be incorrect. Therefore, the solution is not to store calculated values. As these are calculable, they can be calculated at any time - in a query, on a form, or in a report.

If your value is calculable then you don't want to run an UPDATE Query and you don't want to store the value. Just use the expression that calculates it every time a normal SELECT Query is run.
 

Users who are viewing this thread

Back
Top Bottom