I am using access 2000 and trying to create a database to record and track
time spent on jobs to eventually use in payroll.
I have 2 command buttons in the form - one for logon, the other logoff.
I need to be able to record the time on and off when these buttons are
clicked by the employee but am not sure how to do it as I am really only a
beginner with some parts of access
Add a table with 3 fields to the database.
LogID AutoNumber, Indexed No duplicates, Prime Key
TimeLogOn .. DateTime datatype
TimeLogOff .. DateTime datetype
Name the table tblLogTimes
Set the format property of each to
General Date
Add a Command Button to the form.
Name it cmdLogOn
Set it's Caption to "Log On"
Add another Command Button to the form.
Name it cmdLogOff
Set it's Caption to "Log Off"
Make this button Not Visible.
Open the Form's Code window (click View + Code).
Up in the Code's Declaration section, write:
Option Explicit
Dim dteLogOn as Date
===========
Code the cmdLogOn command button click event:
dteLogOn = Now
cmdLogOff.Visible = True
[AControl].SetFocus
cmdLogOn.Visible = False
Code the cmdLogOff Command Button click event:
Dim strSQL As String
strSQL = "Insert into tblLogTimes (TimeLogOn, TimeLogOff) Values (#" &
dteLogOn & "#, #" & Now & "#);"
CurrentDb.Execute strSQL, dbFailOnError
CmdLogOn.Visible = True
[AControl].SetFocus
CmdLogOff.Visible = False
Note: Change [AControl] to whatever the name is of the next control
you wish to go to.
When opened, only the Log On button is visible. When it is clicked, it
becomes not visible and the Log Off button is visible.