This topic is locked

Automatic increase on Add New record

10/19/2006 7:00:08 PM
ASPRunnerPro General questions
hanb author

How to increase an ID field automaticly, when using Add New function, the ID field is defined as varchar, but in fact is a numeric value.

J
Jane 10/20/2006

Hi,
you can do it using AddOnLoad event.

Here is a sample code:

Sub AddOnLoad()

str = "select count(*) from TableName"

Set rsTemp = server.CreateObject("ADODB.Recordset")

rsTemp.open str, dbConnection
Session("id") = rsTemp(0)+1

End Sub



Then use Session("id") as a default value for your ID field on the "Edit as" settings dialog.
Please note that if two people add a new record at the same time both records to have the same ID.
The only reliable way is to use Autonumber field in your database.