autonumber - function

L

learning_codes

Hi,

I will like the function. Is there a way to make it a default as 0 in
the table: tblHighNum.


Public Function isIncrement(ByVal var As Variant) As Long
Dim lng as Long

lng = DLookup("Num", "tblHighNum") + 1
CurrentDb.Execute "UPDATE tblHighNum SET Num = " _
& lng
isIncrement = lng

End Function

Your help would be much appreciated.

Thanks.
 
B

Bob Barrows [MVP]

Hi,

I will like the function. Is there a way to make it a default as 0 in
the table: tblHighNum.


Public Function isIncrement(ByVal var As Variant) As Long
Dim lng as Long

lng = DLookup("Num", "tblHighNum") + 1
CurrentDb.Execute "UPDATE tblHighNum SET Num = " _
& lng
isIncrement = lng

End Function

Your help would be much appreciated.

Thanks.

If your database has multiple users, this approach is a mistake. There is
definitely the potential that two or more users could get the same Ing
number by using this function.

Jet already has an autonumber data type: why try and reinvent the wheel?
 

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