Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save Date and Time Automatically

Status
Not open for further replies.

RSTaylor

Technical User
Apr 17, 2010
19
0
0
US
I have a form called MainBoard. When you open the database this is the first thing you see, and it has several lables that function as buttons and it has a txt box that shows the current date/time as =Now(). I was wondering if there was a way that once the database is opened it would automatically save the date and time to a table, say log, if the form MainBoard had the control sorce of log?
 
How are ya RSTaylor . . .

Use an [blue]AutoExec[/blue] macro to call a routine that appends Now() to the table. The advantage here is that you prevent false positives (opening/closing the form once the db is open).

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
To be honest I don't know a whole lot about Access. Most of what I've done is by trial and error, and some reading. I was playing around with the Macros, and found a save action to save a form and my form MainBoard, but not sure how to "append" the Now() to the table. Would I use the SetValue action?
 
Roger That RSTaylor . . .

I'll try and step you thru it. Be aware ... when a db opens an [blue]AutoExec[/blue] macro runs 1st and we will only be running and [blue]Update SQL[/blue] (whithin the macro).

[blue][tt]Table Setup
***********[/tt]
[/blue]
[ol][li]Open a new table in design view and enter the following:

[tt]FieldName DataType
--------- --------

LogID [blue]AutoNumber[/blue]
DbOpened [blue]Date/Time[/blue] General Tab Format:[blue]GeneralDate[/tt][/blue][/li]
[li]On the toolbar select the [blue]Indexes[/blue] button. The Indexes window opens. If there is a line for LogID, delete that line.[/li]
[li]Be sure the cursor is on the [blue]LogID[/blue] line in the table window and hit the [blue]Primary Key[/blue] toolbar button. A key should show to the left of [blue]LogID[/blue].[/li]
[li]Save the table as [blue]tblLogDbOpened[/blue].[/li]
[li]Be sure to check all spelling! Don't need this kind of error![/li][/ol]

[blue][tt]Macro Setup
***********[/tt]
[/blue]
Open a new macro in design view and enter the following:

[tt]Macro Name Action
---------- ------
UpdateDbLog [blue]RunSQL[/blue][/tt]


SQL Statement [blue]INSERT INTO tblLogDbOpened ( DbOpened ) Values (Now());[/blue]
Use Transaction [blue]No[/blue]

Save the macro as [blue]AutoExec[/blue] and close.


Thats it ... perform your testing! [thumbsup2]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Alright, I'm sorry to keep bothering you. I have a few other fields that I came up with and wanted to add into the table as well. I did a bit more reading and found out that if you wanted to add multiple values it would be

INSERT INTO tblLogDbOpened ( DbOpened, LoginName, Computer, ) Values ( Now(), 'GetCurrentUserName()', 'GetComputerName()', );

Maybe I'm completely wrong with the statement, and obviously I am because I keep getting a 'Syntax error in INSERT INTO statement.'

Am I just such a newbie that I can't manipulate this every which way to make it work somehow? Or am I completely off and need to restructure it somehow?
 
SWEET!!!!!!!!!!!! Never mind, I figured it out. I'm sooo sorry I had to bother you, and I thank you SOOOO much for your help!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top