Changing a value in a table

cfoye130

Board Regular
Joined
Aug 12, 2008
Messages
84
I'm a noob to access VBA so sorry for what seems like an easy question.

On the open of a Form titled "UpdateData" I want to run a macro that will change the value of ID 1, field "Data Update" to a value of 1, in table "Update Status." No idea how to do this but I think it can be done right?

Any help would be greatly appreciated! Thank you!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
To do it in VBA the SQL string would be something like:
Code:
UPDATE Update_Status SET Update_Status.Data_Update = "1"
WHERE (([Update_Status]![ID]="1"));

This is not perfect, but this and some research might get you headed in the right direction before someone corrects my mistakes. Just google SQL update and you can compare some stuff to see if I messed up.

Things to note: Make sure to include the code to connect to the database. Also, you might want to change your table names and field names to either have an underscore or no space at all where there are spaces (kind of like I did with Update_Status). Spaces make SQL stuff go mad!
 
Last edited:
Upvote 0
That works. Thanks. Knew it was something simple.... so why does this not work if I am trying to empty a different field.....

Code:
sql = "UPDATE Update_Status SET Data_Through_Date = NULL WHERE ID=1"
 
Upvote 0
SQL is quite finicky (sp?). Make sure you include the parentheses, brackets, and table refs in the SQL. Try
Code:
UPDATE Update_Status SET Update_Status.Data_Through_Date = NULL
WHERE (([Update_Status]![ID]="1"));

Let me know if that works.
 
Upvote 0
That works. Thanks. Knew it was something simple.... so why does this not work if I am trying to empty a different field.....

Code:
sql = "UPDATE Update_Status SET Data_Through_Date = NULL WHERE ID=1"

you may have the table design setup so that Data_Through_Date cannot be null

also,

do you actually have a column named ID ?
and is that column an integer, a long, or a text field ?

</pre>
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top