Ssanfu, that's approximately what I'm doing already, except I'm trying to do it with a bound control simply because I didn't know any better a few years ago. More specifically, it looks like this:
Code:
' Edit the timestamp to remove "Sent:" and the day of the week from in front.
Private Sub Timestamp_Change()
If bEditingDate Then
bEditingDate = False
Else
vt = Timestamp.Text
pc = InStr(vt, ":")
If pc = 0 Then Exit Sub 'user hasn't entered a time yet
If Len(vt) - pc < 2 Then Exit Sub 'not done entering MM yet
If InStr(vt, " ") = 0 Then vt = Format(Date, "yyyy-mm-dd") & " " & vt
bEditingDate = True
Timestamp.Text = EditDate(vt)
End If
End Sub
This is unnecessarily complicated, I now realize, because I didn't know some things back when I wrote it around 2005. For example, the Boolean flag is necessary to keep the routine from recursing every time I update Timestamp.Text. The documentation said that the Change event isn't triggered by VBA, but I discovered that to be untrue; so I added bEditingDate to kill the recursion. Just this week, however, I discovered that in the 2010 documentation there is a distinction: Changing the Text property triggers the Change event, but changing the Value property in VBA does not. If that turns out to be true, I can simplify this routine even if I stick with Change (although I hope I don't have to).
EditDate is a function I put in a common module because another form uses it too; it's responsible for removing both "Sent:" and the day of the week, if either or both appear.
Those other bits are necessary exactly because I'm using the Change event rather than BeforeUpdate; in case I'm typing in a date and time manually, the code isn't allowed to proceed until I've filled in a colon and two more characters (hour and minutes, you see). But that's a kludge; I'd much rather use BeforeUpdate, especially now that you two have confirmed that it's the better way to go.
Originally Posted by
ItsMe
As for the Now() default, having it at the form level sounds redundant. If your form creates a new record the table will insert the time the record was created by the form (without the form telling the table what the default value is).
"Redundant", I see what you mean now. I liked the idea of seeing what date would be used, before I hit <Enter>; but my programmer's soul is filled with horror at unnecessary redundancy (which term, come to think of it, is itself redundant), so maybe I'll do that after all.
Ok, you two have clarified my mind considerably. I think I can at last put my questions about bound controls cogently—in a separate post.