Can't Assign a Value....Well why not?

Rotten Peaches

New member
Local time
Today, 16:40
Joined
Jul 18, 2012
Messages
8
In Access 2010, when trying to assign a textbox a value using VBA code I'm presented with this error:

Run-time error '-2147352567 (80020009)':
You can't assign a value to this object.
What I'm trying to do is record the date and time whenever a record is modified. I'm using the "Before Update" event to run the following code:

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
DoCmd.SetWarnings (WarningsOff)
Me.txtDateChanged = Date
Me.txtTimeChanged = Time()
End Sub
I don't know why it won't work. This is something that seems about as simple as it gets. I've Googled the error and everyone is suggesting missing references and untrusted locations as the cause but neither of those apply to this as I have no missing references and the location is trusted.

Am I missing something ridiculously obvious?

PS.
In the line "Me.txtDateChanged = Date", Access keeps removing the () behind Date, I don't know why because it leaves them for Time(). I don't know if that has anything to do with the problem.

PPS
If it helps any, I have two different combo boxes on my form. I have one to select location. When you select a location it limits the 2nd combo box's choices. When you make a selection from the 2nd combo box (serial number), the form goes to that specific record.

SOLVED:

Wow...Out of curiosity, I just removed the () from "Me.txtTimeChanged = Time()" and it worked without error.

Sigh....I should have known it was something silly. Thank you everyone for thinking about it!
 
Last edited:
For starters, I don't think you can change values in the before update event. Try the after update event.
 
For starters, I don't think you can change values in the before update event. Try the after update event.

I tried the after update event and although no errors are thrown, the Date/Time doesn't get saved into the table.
 
Check if the two fields are bound to the table? And also AfterUpdate is not the best method to assign values, as it executes after the Form has been updated. You are in the right path of assigning it on the BeforeUpdate. It should not be a problem. Access normaly takes away the () it is not a big deal..
 
Check if the two fields are bound to the table? And also AfterUpdate is not the best method to assign values, as it executes after the Form has been updated. You are in the right path of assigning it on the BeforeUpdate. It should not be a problem. Access normaly takes away the () it is not a big deal..

They're definitely bound. I can enter data into them via the actual table in DataSheet view and it will display on the form.

I too thought the Before Update event should work fine. I just don't know why I'm getting the error...
 
Then make sure they are not read only i.e. check if they have the property allow edits set to be true and check the name of the field is exactly the same.. Sometime the Label will have the same name as the text field with a very small variation.. check if it misspelled..
 
Then make sure they are not read only i.e. check if they have the property allow edits set to be true and check the name of the field is exactly the same.. Sometime the Label will have the same name as the text field with a very small variation.. check if it misspelled..

It's not locked and the names were copied/pasted =\
 
Wow...Out of curiosity, I just removed the () from "Me.txtTimeChanged = Time()" and it worked without error.

Sigh....I should have known it was something silly. Thank you everyone for thinking about it!
 

Users who are viewing this thread

Back
Top Bottom