C
cacacaconnie
instead of using an autonumber is there an expression I can use to find the
highest number plus 1 for my primary key or ID
highest number plus 1 for my primary key or ID
instead of using an autonumber is there an expression I can use to find the
highest number plus 1 for my primary key or ID
John Vinson said:instead of using an autonumber is there an expression I can use to find the
highest number plus 1 for my primary key or ID
One easy way is to use the Form's BeforeInsert event:
Private Sub Form_BeforeInsert(Cancel as Integer)
Me!ID = DMax("[ID]", "[YourTableName]") + 1
Me.Dirty = False ' force a save of the record to disk
End Sub
John W. Vinson[MVP]
Nigel said:Hi John
Found your answer to the previous question really helpful. However, is there
a way to do the same with a combination of letters and numbers: e.g. V101,
V102. I've tried your way but it only seems to work with numbers only.
Thanks
John Vinson said:instead of using an autonumber is there an expression I can use to find the
highest number plus 1 for my primary key or ID
One easy way is to use the Form's BeforeInsert event:
Private Sub Form_BeforeInsert(Cancel as Integer)
Me!ID = DMax("[ID]", "[YourTableName]") + 1
Me.Dirty = False ' force a save of the record to disk
End Sub
John W. Vinson[MVP]
Thomas said:You can just add the code in as:
Me!ID = "V" & DMax("[ID]", "[YourTableName]") + 1
However, this would require that your starting number be 100 or 101. As
it
is currently written, this would start a blank table as "V1".
Nigel said:Hi John
Found your answer to the previous question really helpful. However, is
there
a way to do the same with a combination of letters and numbers: e.g.
V101,
V102. I've tried your way but it only seems to work with numbers only.
Thanks
John Vinson said:On Mon, 23 Oct 2006 10:04:02 -0700, cacacaconnie
instead of using an autonumber is there an expression I can use to
find the
highest number plus 1 for my primary key or ID
One easy way is to use the Form's BeforeInsert event:
Private Sub Form_BeforeInsert(Cancel as Integer)
Me!ID = DMax("[ID]", "[YourTableName]") + 1
Me.Dirty = False ' force a save of the record to disk
End Sub
John W. Vinson[MVP]
Douglas J. Steele said:Actually, as currently written, it would start a blank table with V, because
DMax would return Null.
You need
Me!ID = "V" & Nz(DMax("[ID]", "[YourTableName]"), 0) + 1
to handle the Null value.
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Thomas said:You can just add the code in as:
Me!ID = "V" & DMax("[ID]", "[YourTableName]") + 1
However, this would require that your starting number be 100 or 101. As
it
is currently written, this would start a blank table as "V1".
Nigel said:Hi John
Found your answer to the previous question really helpful. However, is
there
a way to do the same with a combination of letters and numbers: e.g.
V101,
V102. I've tried your way but it only seems to work with numbers only.
Thanks
:
On Mon, 23 Oct 2006 10:04:02 -0700, cacacaconnie
instead of using an autonumber is there an expression I can use to
find the
highest number plus 1 for my primary key or ID
One easy way is to use the Form's BeforeInsert event:
Private Sub Form_BeforeInsert(Cancel as Integer)
Me!ID = DMax("[ID]", "[YourTableName]") + 1
Me.Dirty = False ' force a save of the record to disk
End Sub
John W. Vinson[MVP]
John Vinson said:instead of using an autonumber is there an expression I can use to find the
highest number plus 1 for my primary key or ID
One easy way is to use the Form's BeforeInsert event:
Private Sub Form_BeforeInsert(Cancel as Integer)
Me!ID = DMax("[ID]", "[YourTableName]") + 1
Me.Dirty = False ' force a save of the record to disk
End Sub
John W. Vinson[MVP]
I try your code but it not work in my database I tblAllottees in which
primary key ID is AID with Data type Number
John Vinson said:instead of using an autonumber is there an expression I can use to find the
highest number plus 1 for my primary key or ID
One easy way is to use the Form's BeforeInsert event:
Private Sub Form_BeforeInsert(Cancel as Integer)
Me!ID = DMax("[ID]", "[YourTableName]") + 1
Me.Dirty = False ' force a save of the record to disk
End Sub
John W. Vinson[MVP]