AfterUpdate Event or what?

G

Guest

Good afternoon, group!

I have a simple bundy clock application where employees should enter their
ID numbers via keyboard ( we don't have chronolog/swiping machines). My
database has a table named TIME with the following fields:

Time_ID (Autonumber)
DateWorked (Date/Time)
Am_In(Date/Time) default value is TimeValue(Now())
Am_Out (Date/Time) default value is 12:00 Pm
Pm_In (Date/Time) default value is 13:00
Pm_Out (Date/Time) default value is TimeValue(Now())

Now, how can I instruct the program to save the current time when they press
the enter key after typing their ID number without manually keying in the
time?

Here's how the user interface look:
The opening form is an unbound form where they enter their ID Number. After
pressing the enter key, a form named "DTR" opens. The DTR form contains the
employee's IDNumber, Photo, name and position. The form DTR also has a
subform named Time subform where Time in/Time Out is located.

Please help and thank you very much!
 
G

Guest

On the after update event of the key field write the code

' To insert time
Me.[TimeFieldName] = Time

' To insert Date and time
Me.[TimeFieldName] = Now()
 
H

HKComputer

This may not apply to you but in cases of unbound forms you will need
to use SQL statements. INSERT INTO is used to create new records and
UPDATE is used to update data in a field or fields in an existing
record.

Here is an example of a statement I'm using to update a record in a
table named tblHDate. intGuestID and intHDateID are both variables.
While SQL is simple, its syntax when used in VBA is always a challenge
for me to figure out.

DoCmd.RunSQL "Update tblHDate Set tblHDate.GuestID = (" & intGuestID &
") WHERE HDateID = (" & intHDateID & ")"

I also would recommend that you don't name your table TIME. I believe
TIME is a reserved name. You could run into problems if you use code
to refer to this table. I suggest you use the standard naming
convention and call it tblTime.
 
G

Guest

Hi, Guys! Good evening!

Thank you very much for the prompt reply and I really appreciate your help.
I find all your suggestions helpful. There's another problem, though. How
can I instruct the program to reject Time In/Time Out once a user has already
punched in or out? I am just having problems with employees trying to enter
2 or more Time Ins. I hope you could help me with this again and thank you
very much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top