Is there a way to have a form record date/time only on first entry? (1 Viewer)

stell

Registered User.
Local time
Today, 03:20
Joined
Jun 14, 2017
Messages
15
Hello. I have a form I am using for data entry, and it records the date and time every time there is a new entry. However, there are instances where people may have to go back and change information in a record. Whenever this happens, the date/time updates to whatever time the modification was made. Can anyone help me find a solution so the date/time does not update when the modification is made? Right now I am using a 'before update' event to record the date/time.

Thank you.
 

isladogs

MVP / VIP
Local time
Today, 11:20
Joined
Jan 14, 2017
Messages
18,207
Add a condition to only populate the date field where it is null
 

plog

Banishment Pending
Local time
Today, 05:20
Joined
May 11, 2011
Messages
11,634
Whenever this happens, the date/time updates to whatever time the modification was made.

Don't do this then.

Right now I am using a 'before update' event to record the date/time

Don't do this either. Just set the default value for this field at the table level. When the record is created it gets the Date/Time. Coding often isn't the solution.
 

stell

Registered User.
Local time
Today, 03:20
Joined
Jun 14, 2017
Messages
15
Add a condition to only populate the date field where it is null

Thanks for the response, I believe this will solve my problems. I tried changing up my programming but I seemed to have messed something up. Does this pic look right?

EDIT: disregard. I figured out I should be using "is null" instead of using the equal sign
 

Attachments

  • ACCESS.PNG
    ACCESS.PNG
    5.3 KB · Views: 128
Last edited:

stell

Registered User.
Local time
Today, 03:20
Joined
Jun 14, 2017
Messages
15
Don't do this then.



Don't do this either. Just set the default value for this field at the table level. When the record is created it gets the Date/Time. Coding often isn't the solution.

Thanks for the response, problem with this method is that the second they create a new record it will record the time/date, even if they don't necessarily enter the data until later.
 

isladogs

MVP / VIP
Local time
Today, 11:20
Joined
Jan 14, 2017
Messages
18,207
Thanks for the response, problem with this method is that the second they create a new record it will record the time/date, even if they don't necessarily enter the data until later.

There's no reason for the date/time to be recorded automatically.
You can disable or modify the code that is doing that.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:20
Joined
Feb 19, 2002
Messages
43,196
If you want to separate the CreateDT from the ChangeDT, you need two columns. The CreateDT should use a table level default of Now(). The ChangeDT should be populated in the Form's BeforeUpdate event.

If you want to stick with a single control that is only updated when the record is added, you'll need to either remove the code entirely and use the table level default or have the code check whether or not this is a new record.

PS, Date and Time should not be separate fields and more importantly, Function names should NEVER be used as column names. Using Date and Time for column names leads to subtle errors if you for get to encase the offending names in square brackets. You could end up getting today's date rather than the date from the record if you use date rather than [date] in code.

Use a single field. Name it something meaningful such as TimeIn (whatever makes sense for your purpose), define it as a Date data type and set its default to Now() which includes BOTH date AND time. Date() is ONLY date. Time() is ONLY time.

Every application I build logs dates automatically. Usually it is only CreateDT and ChangeDT but other instances might be SaleDT or LogInTime. Dates such as CreateDT and ChangeDT can NEVER be changed by the user but other automatic dates can although some might require special security and generate a log record. Time keeping applications are one example. The user clocks in and the app captures the date and time. If he wants that to be changed, he has to convince a supervisor that he was actually in earlier and simply forgot to log in so the app captures the Supervisor, the change reason and the original value and logs it.
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:20
Joined
May 7, 2009
Messages
19,226
use IsNull([Date]) on your macro.
 

missinglinq

AWF VIP
Local time
Today, 06:20
Joined
Jun 20, 2003
Messages
6,423
Can anyone help me find a solution so the date/time does not update when the modification is made? Right now I am using a 'before update' event to record the date/time.

If you don't want to use the Default Value Property, the other pretty much standard way would be to only assign the date when the Record is a New Record:

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

 If Me.NewRecord Then
   Me.DateCreated = Date
 End If

End Sub

Linq ;0)>
 

Users who are viewing this thread

Top Bottom