This topic is locked

Problems with adding New Record

11/30/2009 6:10:10 AM
ASPRunnerPro General questions
M
marchino author

Hi everyone,

I'm working on a MS Access Db of a client. This Db has in his tables all the primary id keys set with simple text fields (and not with autoincrement values). To add a new record I know that previously it was used a function (or something similar). This method consisted (more or less) in reading the last Id number, increment 1 and write it automatically in the new record.

Did anyone ever faced something like this before? Can I do something similar (maybe in Access with a query) and use it in ASpRunner?

Any suggestion will be very appreciated.....

Marco
Actually I did some research and I found out it is a quite common situation, a Custom AutoNumber field.... (but the problem remains!!!!)

Sergey Kornilov admin 11/30/2009

You need to use events for this purpose, namely BeforeAdd event. You can select the max ID from this table and increment it by one.

Here is the sample code.



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

rstmp.open "select max(id)+1 from tablename",dbConnection
values("id") = rstmp(0)
rstmp.close

set rstmp=nothing
D
dunga 12/11/2009

Hi, I have exactly same issue, I followed the advise here

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

rstmp.open "select max(RequestID)+1 from EducationRequests",dbConnection

values("RequestID") = rstmp(0)

rstmp.closeset

rstmp=nothing


My RequestId field is set as Number in Access, when i tried to add a record I got the

Error Type:

Microsoft VBScript runtime (0x800A01B6)

Object doesn't support this property or method: 'rstmp.closeset'

/ES20101/include/EducationRequests_events.asp, line 118


I have also checked the visual editor and set view as number,
What could be the issue here?
Thanks

Sergey Kornilov admin 12/12/2009

Wrong:

rstmp.closeset

rstmp=nothing
Right:

rstmp.close

set rstmp=nothing
Hint: Error messages contain hints pretty often.