How to enter a processing date into a Form

  • Thread starter Thread starter Art Cav
  • Start date Start date
A

Art Cav

When I open my Form I would like to enter a processing date
that could be added to each update record
 
Art Cav said:
When I open my Form I would like to enter a processing date
that could be added to each update record

Do you mean you want the user to enter the processing date into a text
box on the form, and then that date will be copied into each record that
is subsequently modified on that form? Or do you just want the current
date to be stamped into each updated record?

If it's the former, you can put an unbound text box on the form, call it
maybe "txtProcessingDate", and set its Format property to one of the
date formats. You also need to have a date field in the table to which
the field is bound. Perhaps that field would be called "DateProcessed".
Then create an event procedure for the form's BeforeUpdate event, with
code similar to this:

'---- start of example code ----
Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull(Me.txtProcessingDate) Then

MsgBox _
"You must fill out the processing date before the " & _
"current record can be saved.", _
vbInformation, "Entry Required"

Cancel = True

Me.txtProcessingDate.SetFocus

Else

' Get the processing date for the record from
' the unbound control.
Me.DateProcessed = Me.txtProcessingDate

End If

End Sub
'---- end of example code ----
 
If this date should always contain the last date that the record was edited,
use the Before Update event procedure of the form to assign the date:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.[processing date] = Date
End Sub

If you want it to contain the date and time, use Now() instead of Date.
 
Your assumption was correct. I added your code but the
message box does't open. Why???
Art
 
Your assumption was correct. I added your code but the
message box does't open. Why???

I can only think of three reasons. Either txtProcessingDate is not
Null -- does it have a default value? -- or the form's BeforeUpdate
event didn't fire at all -- did you modify a bound control on the form,
so that the record needed to be saved? -- or there's an error in the
code such that it didn't even compile -- did you create the field
"DateProcessed" and the control "txtProcessingDate" as I described them?
If you click Debug -> Compile, do you get any errors?

You could set a breakpoint at the top of the event procedure, trigger it
by modifying and saving a record, and step through the code examining
values and observing the path it takes. That might tell you something
about why you're not getting the message box when you expect to.
 
Back
Top