Update a table the 1st time the db is opened

H

Hlewis

I have an update query that I want to run the first time a db is opened.
This of course will be based on rather or not a linked table has been updated
for that day. How can I do this?
 
K

Klatuu

Hopefully, you have a field in the table that has a date field that
identifies the date the record was updated.

You can then test to see if the record has been updated for the current date
and only run the query if it has not.
 
O

Ofer

How can you tell if the data been updated already?

Create a function in a module

Function FunctionName()
If NotDataChanged Then
Docmd.OpenQuery "UpdateQueryName"
End If
End Function
======================
You can call this functions from two places
1. Create a macro called Autoexec, and set the properties in it to run the
function
2. If you use the StartUp of the MDB to open a form when the mdb opens, then
you can call this function on the OnLoad event of the main form
 
H

Hlewis

Ofer,

I can't tell if the data has been updated. I usually have to look at the
data to tell. I there a systematic way to do this?
 
O

Ofer

Just a Klatuu replied, the best way is to add another field to the table,
Last_Updated, and when you update the table, update this field, assign to it
the value Date()

So you IF statement can look like

If DCount("*","TableName","Last_Updated = #" & Date() & "#") = 0 Then
Run update query statement here
End If
 
Top