Help with error in vba code

G

gvaughn

I am having a problem with some codwe in vba.

I am trying to change the mass weight in a table to the value set in a text
box.

My code for the click_event is:

Tables![dbo_ToteView]![Mass] = Me.tbValueToEnter

It recongizes the value but will not add the value to that table. The error
message is that Tables![dbo_ToteView]![Mass] = <Object Required>. Any
suggestions on how to fix this problem and why is it not liking the object I
am trying to reference. Thank you
 
D

Dirk Goldgar

gvaughn said:
I am having a problem with some codwe in vba.

I am trying to change the mass weight in a table to the value set in a
text
box.

My code for the click_event is:

Tables![dbo_ToteView]![Mass] = Me.tbValueToEnter

It recongizes the value but will not add the value to that table. The
error
message is that Tables![dbo_ToteView]![Mass] = <Object Required>. Any
suggestions on how to fix this problem and why is it not liking the object
I
am trying to reference. Thank you


You can't change a value in a table directly like that. To change the
value, you can execute an update query -- whether a stored query or a SQL
statement constructed on the fly -- or you can open a recordset on the table
(or a query of it), edit the record, and update it, or you can have form
bound to the table and modify the value of a field on the form.

In what context are you trying to do this? It looks like the code is
running on a form; is that form bound to the table you want to update?
Does the table contain more than one record, and do you want to update them
all or only a specific one?
 
G

gvaughn

Yes the form is bound to the table and I only want to change one specific
mass at a time. Basically the mass is 200lbs, but if someone spills a bag, or
a bag is damaged than it needs to be re-weigh and a new mass put in. they
will be doing this from the form itself. It doesn't happen very often, but it
does happen and it is a problem that needs fixing. Thank you

Dirk Goldgar said:
gvaughn said:
I am having a problem with some codwe in vba.

I am trying to change the mass weight in a table to the value set in a
text
box.

My code for the click_event is:

Tables![dbo_ToteView]![Mass] = Me.tbValueToEnter

It recongizes the value but will not add the value to that table. The
error
message is that Tables![dbo_ToteView]![Mass] = <Object Required>. Any
suggestions on how to fix this problem and why is it not liking the object
I
am trying to reference. Thank you


You can't change a value in a table directly like that. To change the
value, you can execute an update query -- whether a stored query or a SQL
statement constructed on the fly -- or you can open a recordset on the table
(or a query of it), edit the record, and update it, or you can have form
bound to the table and modify the value of a field on the form.

In what context are you trying to do this? It looks like the code is
running on a form; is that form bound to the table you want to update?
Does the table contain more than one record, and do you want to update them
all or only a specific one?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

gvaughn said:
Yes the form is bound to the table and I only want to change one specific
mass at a time. Basically the mass is 200lbs, but if someone spills a bag,
or
a bag is damaged than it needs to be re-weigh and a new mass put in. they
will be doing this from the form itself. It doesn't happen very often, but
it
does happen and it is a problem that needs fixing. Thank you

If the form is bound to the table, then don't you have a text box on the
form that is bound to the Mass field? If so, all you have to do is edit the
value displayed in that text box, and that value will automatically be saved
the when you either move to a new record, close the form, or do any of
several user-interface actions that tell Access to save the record.

I may be missing something, because there is no need for code to accomplish
this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top