View Full Version : [SLEEPER:] How can I update a table each time I run a query?
keek2a4
12-05-2007, 05:05 AM
Hello Everyone!
I am using Microsoft access and I have a table with two fields: ID and Date. The ID is set to autoincrement.
How can I update a table with the next ID and date to current, each time a query is run.
Thanks,
Ket
mattj
12-05-2007, 08:10 AM
First thing to do would be to change the name of the "Date" field. Date is a reserved word in Access and could cause problems...
Assuming that this qeury is run from some event, just execute an Append query after the code that runs the first query:
CurrentDb.Execute "INSERT INTO your table ( YourDateField )
SELECT Date();", dbFailOnError
keek2a4
12-05-2007, 08:48 AM
yep, thats the exact query I was after. I have another question that is If I wanted to run or execute this query in vba, how can i go about in doing that? Thanks for your help
mattj
12-05-2007, 08:55 AM
Thats what I posted...
keek2a4
12-05-2007, 09:20 AM
aah sorry my mistake i wasn't paying attention. Thanks:mayi:
mattj
12-05-2007, 09:22 AM
np :thumb
keek2a4
12-05-2007, 10:01 AM
I finally have one last question,
If I have a query that displays the ID and Date, how can I set a criteria that only displays the last date record.
Hence, for example if I have a query that displays
ID Date
01 01/02/02
02 02/02/02
03 03/02/02
I want to set a criteria that only displays the last record with the latest date, which is
ID DATE
03 03/02/02.
Thanks,
Ket
mattj
12-05-2007, 10:54 AM
In your query, enable the Totals icon, then in the Date column, select MAX.
Norie
12-05-2007, 11:29 AM
Ket
Why do you want/need to update the date each time you run the query?
Couldn't you just add a field for the current date to the query?
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.