New record, last date +1

R

Rob

Hi,

I have a form with a date field. I want that when I open a new record it
looks for last date in previouse record and then add 1 day. I am shore it is
some simple one that I have not found out.

//Robert
 
S

Stefan Hoffmann

hi Rob,
I have a form with a date field. I want that when I open a new record it
looks for last date in previouse record and then add 1 day.
Depends on your definition of "previous record". If you have an
autoincrement primary key, this may work:

CDate(DLookup("DateField", "Table", "ID = " & _
DMax("ID", "Table") + 1)



mfG
--> stefan <--
 
S

Stefan Hoffmann

hi,
Depends on your definition of "previous record". If you have an
autoincrement primary key, this may work:

CDate(DLookup("DateField", "Table", "ID = " & _
DMax("ID", "Table") + 1)
There is a ) missing:

CDate(DLookup("Date", "Table", "ID=" & DMax(..)) + 1)

mfG
--> stefan <--
 
R

Rob

Hi Stefan

I put in the date myself in the field. I only want that when I create a new
record I automaticlly get the date after the last I filled in or got by auto.

//Robert

"Stefan Hoffmann" skrev:
 
B

BruceM

By "the last I filled in or got by auto" do you mean the record with the
most recent date? If so, your form's Current event could be:
If Me.NewRecord Then
Me.DateField = DMax("DateField","TableName") + 1
End If

The expression DMax("DateField","TableName") + 1 could also be used as the
default value for DateField. In either case, each new record will have a
date one greater than the previous most recent date. If you create ten
records during one day, you will have ten sequential dates in that field.
Is that your intention?
 
R

Rob

Thank you all. It works create

"BruceM" skrev:
By "the last I filled in or got by auto" do you mean the record with the
most recent date? If so, your form's Current event could be:
If Me.NewRecord Then
Me.DateField = DMax("DateField","TableName") + 1
End If

The expression DMax("DateField","TableName") + 1 could also be used as the
default value for DateField. In either case, each new record will have a
date one greater than the previous most recent date. If you create ten
records during one day, you will have ten sequential dates in that field.
Is that your intention?
 
Top