Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Now()

Status
Not open for further replies.

DonLo

Technical User
Apr 24, 2001
36
0
0
US
I have a form that I use for entering data on sales of an item. On that form I have two fields, "CreatedDate" and "ChangedDate" which are locked and set by the following code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me!ChangedDate = Now()
End Sub

Private Sub Form_BeforeInsert(Cancel As Integer)
Me!CreatedDate = Now()
End Sub

The problem is that, when the main user of this form begins inputing data on a new day, this code doesn't properly set the CreatedDate for the first few records. The ChangedDate field is properly set. The problem corrects itself after a few records (anywhere from 2 to 8, so far).

I thought that somehow, an incorrect date might be stored in memory, so I tweaked the CreatedDate code as follows:

Private Sub Form_BeforeInsert(Cancel As Integer)
Dim DateTime As Date
DateTime = Now()
Me.CreatedDate = DateTime
End Sub

but the problem still persists.

Can anyone help me out here?

Thanks for your ideas!

Don
 
It may be the event type you are using. Can you not change this to On_Load / On_Open?

------------------------
Hit any User to continue
 
Thanks for this suggestion. I just tried this out, however, it only sets the date for the very first record entered, not any of the subsequent records.

Don
 
try setting the ControlSource of these text boxes to Now()

------------------------
Hit any User to continue
 
Thanks SiJP, but I need to record this date, so I'm using bound textboxes.

Don
 
Try the default format with Now()

Hope this helps
Hymn
 
Thanks hymn. I assumed you meant default value, which seems to work. I'll have to let this run for a few days to make sure if fixes the original problem.

I'm still a bit baffled as to why my original approach had problems, but....

Don
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top