Locking an autodate

G

GD

Is the code below correct if I want a date to autofill, but then never change
unless done manually? Also, does it go in the Form Current event, too?

Private Sub cboEnteredBy_AfterUpdate()
If Me.NewRecord Then
Me.txtEntryDate = Now
End If

End Sub
 
J

Jeff Boyce

The code you offer appears to (re-)set the txtEntryDate EVERY TIME the
cboEnteredBy changes...

Is that what you're after?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
J

Jeff Boyce

One of these days I'll learn to read before typing. Your code does, very
clearly, mention .NewRecord...

I take back my earlier blurt...

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
G

GD

Forgive my ignorance (I should probably have entered my question in "New
Users", since I'm still a newby at this), but I see 2 potential problems with
Doug's suggestion:

A) Doesn't Date() & Now() assume current date and time, and therefore
wouldn't entering one or the other as the default value of txtEntryDate cause
the date and/or time to change every time the record is opened? Maybe I have
a faulty understanding of the 2 functions.

B) When I use Date() as the default value of txtEntryDate, the date appears
before cboEnteredBy is updated. I need it to appear as that field is updated.

Thanks!!
 
D

Douglas J. Steele

A) Default Values only apply when no value exists in the field. When a new
record is created, Access will see that there's no value for txtEntryDate,
and will populate it with the appropriate value. Any further use of that row
will contain the value assigned when the record was created.

B) If you're using Date, that should only be an issue if someone starts
creating a record before midnight, but doesn't select a value from
cboEnteredBy until after midnight. Will that really an issue for you? (I
could see perhaps being concerned if you were using Now, rather than Date)

Incidentally, is there a reason why you're making the user select from a
combo box? You can write a function that returns the user's Windows Network
ID. (See http://www.mvps.org/access/api/api0008.htm at "The Access Web" for
details). Unfortunately, though, you won't be able to use that function as a
Default Value. What you can do instead is put code in the form's
BeforeUpdate event to set the field.
 
G

GD

Sounds good. Thanks, Doug!
--
GD


Douglas J. Steele said:
A) Default Values only apply when no value exists in the field. When a new
record is created, Access will see that there's no value for txtEntryDate,
and will populate it with the appropriate value. Any further use of that row
will contain the value assigned when the record was created.

B) If you're using Date, that should only be an issue if someone starts
creating a record before midnight, but doesn't select a value from
cboEnteredBy until after midnight. Will that really an issue for you? (I
could see perhaps being concerned if you were using Now, rather than Date)

Incidentally, is there a reason why you're making the user select from a
combo box? You can write a function that returns the user's Windows Network
ID. (See http://www.mvps.org/access/api/api0008.htm at "The Access Web" for
details). Unfortunately, though, you won't be able to use that function as a
Default Value. What you can do instead is put code in the form's
BeforeUpdate event to set the field.
 

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