New Record, last Date + 1 different records

  • Thread starter Thread starter glnbnz
  • Start date Start date
G

glnbnz

I have a datefield in a form that I would like to have autofilled when I
enter a new record. Right now I have something like this:
If Me.NewRecord then
Me.DateGauged = DMax("DateGauged","tblGaugesInput") + 1
End if

My problem is that it just looks for the max date of the whole table. I
would like to narrow it down to a specific group of records in the table and
do the last date + 1 on that group: Example of my table.
TankNumber DateGauged Measurement
8555 2/1/2008 8"
8555 2/2/2008 9"
8556 2/1/2008 7"

So when I open my add form for tank 8556 I would like for it have 2/2/2008
in the DateGauged field. The way I have it written it will put in 2/3/2008.
Please help.

Thank you
glnbnz
 
Take a look at Access HELP for the syntax on the DMax() function.

I seem to recall that there's a "WHERE" clause you can add after the
table...

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Jeff,
Thanks for the advice. I did find what I needed on the MSDN website when I
did a search for DMax function. Here is my final code:

If Me.NewRecord Then
Me.DateGauged = DMax("DateGauged", "tblGaugesInput", _
"[TankNumber]= " & "forms!frmAddGauge1!TankNumber") + 1
End If

Now it works great. Thanks again.
glnbnz
 
Back
Top