automatic enter a date plus one day from the previous record


B

Bill

I use a data base using the date as the indexI want to automatically enter
previous date plus one day on my data entry form at new record creation. is
there an easy way ?
 
Ad

Advertisements

A

Allen Browne

Use the BeforeInsert event procedure to look up the highest date so far, and
enter the next value.

This example assumes the field/control is named Date1, and comes from
Table1:

Private Sub Form_BeforeInsert(Cancel As Integer)
Dim varResult As Variant

If Not Form.ActiveControl Is Me.Date1 Then
varResult = DMax("Date1", "Table1")
If IsDate(varResult) Then
Me.Date1 = varResult + 1
End If
End If
End Sub

(Note that the code avoids assigning the date if Date1 is the active
control, as it gets really confusing if the user is trying to type something
into that box and another value suddenly shows up.)
 

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