Link to home
Start Free TrialLog in
Avatar of deer777
deer777Flag for United States of America

asked on

MS Access VBA coding to update field

I have got a form that is loading records to a table by endusers.  Each time a new record is created I would like the new record StartTime field to reflect the previous record EndTime value.  At the end of the day all records are loaded to the main table for reporting purposes soooooooooooooo all of the todays records are for today's date.

Currently, the EndTime is reflected in the StartTime field and I need it to be reflected every time the user enters a new record.  How can I code that to always put the EndTime of the previous record in the new record StartTime field?
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

How are you creating the new record?

with an insert statement, you might do something like:

INSERT INTO yourTable (field1, Field2, Field3, StartTime)
Values (Field1, Field2, Field3, DMAX("StartTime", "yourTable", "DateValue([EndTime]) = #" & date() & "#"))

Open in new window


However, if this is a multi-user database, then you might have users step on each other by simultaneously running this query, which would return the same startTime form multiple records.  If that is the case, would you want the values for the previous records to apply to the specific individual who is entering the data?
Avatar of deer777

ASKER

Currently I have a split database which I run a local table on each of the users FE database located on their desktop.  They each have a form that they enter data into (each record has a StartTime field and an EndTime field).  The Main table is linked but the local table stores all their records for the day until at the end of the day they load their data from their local table to the linked main table located in the BE database so there is no worry about other user data getting confused with current users data.

I have code under Form Current as :

Dim dtEndTime As Date

If me.newrecord then Me.StartTime = dtEndTime

This method works most all of the time but mostly screws up on the second record.  I need it to work every time.
How can I make this happen?
Avatar of deer777

ASKER

The StartTime field and the EndTime field format is for the time.
ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deer777

ASKER

Yes, each user clicks on the load button on the form which the code loads all the data from the local table to the linked main table every day.
I will try this code

Thanks much!
Avatar of deer777

ASKER

Excellent fix, Dale!
glad to help.