I read the article you posted the reference to.
Notice the DLookup method has this disclaimer:
This technique assumes that you have a table with an ID field of a Number
data type, and that the ID values are not missing any number (or numbers) in
sequential order.
You are using a data type and cannot be sure there are not missing dates.
The code version is assuming you are selecting an existing record and moving
to the previous record. Previous record means in the current sort order.
Since you are adding a new record, this will not work for you. Try this:
Private Sub Form_Current()
Dim varTempDate As Variant
If Me.NewRecord And IsNull(Me.DOS) Then
varTempDate = DMax("[DOS]", "InputData")
If IsNull(varTempDate) Then
Me.DOS = Date()
Else
Me.DOS = DateAdd("d", 1, varTempDate)
End If
End If
End Sub
Now, the issue I see is there will only ever be one record in this table for
any date. Is that what you want?
varLastDate = DMax
sneagle said:
Thanks for all the replies. The code by tina and Marshall did not work. I
cut and paste so I don't think I made a typo.
As for Klatuu's comments...the idea of checking to see is DOS is null is to
be sure it is a new record. Otherwise, I would be changing already entered
dates. As for looking at the previous record, it should be feasible. See
here:
http://support.microsoft.com/?kbid=210504
Meanwhile, any other suggestions on how to make this work. If I can't, no
big deal, it was really just for user convenience.