bumper338 said:
Good day all,
I am not sure if I should post this question here or not. What I would
like
to know is how would I create a command button to copy the current time
value
into a table. For example, you click on the button and it records the
time
the entry was made automatically.
It's not clear to me whether you want to add a new record to this table or
update an existing one. And it could also be that you just want to insert
the time into a field in the current record on a form. I don't know which
of these you want to do, if any, so I'll give you examples for all three:
'----- start of code to insert record in table -----
Private Sub cmdInsertTime_Click()
CurrentDb.Execute _
"INSERT INTO YourTable (YourTimeField) Values(Now())", _
dbFailOnError
End Sub
'----- end of code to insert record in table -----
'----- start of code to update record in table -----
Private Sub cmdUpdateTime_Click()
CurrentDb.Execute _
"UPDATE YourTable " & _
"SET YourTimeField = Now() " & _
"WHERE YourIDField = " & YourIDValue, _
dbFailOnError
End Sub
'----- end of code to update record in table -----
'----- start of code to update a field in the form's current record -----
Private Sub cmdUpdateTimeOnForm_Click()
Me!YourTimeField = Now()
End Sub
'----- end of code to update a field in the form's current record -----
NOTE: all of the above examples use the Now() function, which returns the
current date *and* time. If you want the time alone (which is actually
returned as the time on "date 0" -- December 30, 1899), you can use the
Time() function instead of the Now() function.