Change unsaved value during save process?

David R

I know a few things...
Local time
Yesterday, 19:20
Joined
Oct 23, 2001
Messages
2,633
I must be rusty, because this seems like the simplest thing in the world.

I have date fields on my new form. Data validation requires them to have a 'time' associated with them. I thought I could trap if they had left the time portion blank and insert the current time of day, rather than forcing them to go back to the field and re-enter it (these are not power users).
Code:
'first put in a time of day if they forgot to do so
    If Me.CaseAwarded.Value = Date And Hour(Me.CaseAwarded.Value) = 0 Then Me.CaseAwarded.Value = Now()
Default = Now() won't work because they might be backdating.

http://office.microsoft.com/en-us/access/HA102389881033.aspx#1 says that BeforeUpdate is the earliest event that fires when you start to save a field/record; but that's too late (Error 2115). Someone in an earlier thread suggested OnLostFocus but that happens even later. The OnChange event happens on every keystroke. What am I missing??
 
How about using the After Update event of the control? So, let's say they put the date only in and then tab or click to another control then the After Update of that previous control could first check to see if there is a full date/time and if not add the time. (You don't want to do it without checking for a full date/time because then you could get stuck in a loop as it updated the control again and then again and again).
 
That'd work except that the next step of the BeforeUpdate is to compare the tiimestamp to the previous step of our process. Since DateClosed:#3/30/2010 12:00:00 AM# is before DateInspected:#3/30/2010 12:37:14 PM#, that'll cause validation to fail every time (which is why they have to put a timestamp in to begin with).
 

Users who are viewing this thread

Back
Top Bottom