Here is what I'm trying to do...

Open a recordset (the code is more complex this is only one possible
path)
if it is an empty recordset then add a new record, and put values in
that record, update that record, and finally grab the autonumber value
for use in the next block of code.

'OPEN db

Set objConn = Server.CreateObject("ADODB.Connection")
path = server.MapPath("TCSDB.mdb")
objConn.Open = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" &
path
'set up recordset

set rsPutStaticCostSheetFields =
server.createobject("adodb.recordset")
strSQL = "select * from CostSheets"
rsPutStaticCostSheetFields.open strSQL, objConn, 2, 2
'oh its a new record. recordset has correct table / columns open

rsPutStaticCostSheetFields.addNew
'add new column values

rsPutStaticCostSheetFields.update
'TRY TO GET AUTONUMBER FIELD (FIRST COLUMN CALLED "CostSheetID")

tmpCostSheetID = rsPutStaticCostSheetFields("CostSheetID")
response.write(tmpCostSheetID&"<-- first try<br>")
tmpCostSheetID = rsPutStaticCostSheetFields.Fields.Item("CostSheetID")
response.write(tmpCostSheetID&"<-- second try<br>")
tmpCostSheetID = rsPutStaticCostSheetFields(0)
response.write(tmpCostSheetID&"<-- third try<br>")
tmpCostSheetID = rsPutStaticCostSheetFields("CostSheetID").value
response.write(tmpCostSheetID&"<-- fourth try<br>")
rsPutStaticCostSheetFields.close
...
<-- first try
<-- second try
<-- third try
<-- fourth try
I see no values. Any ideas? Am I using the wrong kind of cursor to
access the access database?

Thanks in advance for your help.
Greg.

"Sometimes we need to kick at the darkness till it bleeds daylight"

Re: getting autonumber value when using addnew by Bob

Bob
Thu Sep 18 10:52:23 CDT 2003

Greg wrote:
> Here is what I'm trying to do...
>
> Open a recordset (the code is more complex this is only one possible
> path)
> if it is an empty recordset then add a new record, and put values in
> that record, update that record, and finally grab the autonumber value
> for use in the next block of code.
>
http://www.aspfaq.com/show.asp?id=2174
Scroll down to the Access section

HTH,
Bob Barrows



Re: getting autonumber value when using addnew by Walter

Walter
Thu Sep 18 11:04:31 CDT 2003

Try changing the 3rd parameter of the open method from 2 (adOpenDynamic) to
1 (adOpenKeyset) and see if that helps. Not all (if any) Jet versions
support ADO's adOpenDynamic cursor. Depending on other factors, you may get
either a static or dynamic cursor when using adOpenDynamic.

"Greg" <gregmckone@yahoo.com> wrote in message
news:3816e6d1.0309180701.3d7eb69b@posting.google.com...
| Here is what I'm trying to do...
|
| Open a recordset (the code is more complex this is only one possible
| path)
| if it is an empty recordset then add a new record, and put values in
| that record, update that record, and finally grab the autonumber value
| for use in the next block of code.
|
| 'OPEN db
|
| Set objConn = Server.CreateObject("ADODB.Connection")
| path = server.MapPath("TCSDB.mdb")
| objConn.Open = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" &
| path
| 'set up recordset
|
| set rsPutStaticCostSheetFields =
| server.createobject("adodb.recordset")
| strSQL = "select * from CostSheets"
| rsPutStaticCostSheetFields.open strSQL, objConn, 2, 2
| 'oh its a new record. recordset has correct table / columns open
|
| rsPutStaticCostSheetFields.addNew
| 'add new column values
|
| rsPutStaticCostSheetFields.update
| 'TRY TO GET AUTONUMBER FIELD (FIRST COLUMN CALLED "CostSheetID")
|
| tmpCostSheetID = rsPutStaticCostSheetFields("CostSheetID")
| response.write(tmpCostSheetID&"<-- first try<br>")
| tmpCostSheetID = rsPutStaticCostSheetFields.Fields.Item("CostSheetID")
| response.write(tmpCostSheetID&"<-- second try<br>")
| tmpCostSheetID = rsPutStaticCostSheetFields(0)
| response.write(tmpCostSheetID&"<-- third try<br>")
| tmpCostSheetID = rsPutStaticCostSheetFields("CostSheetID").value
| response.write(tmpCostSheetID&"<-- fourth try<br>")
| rsPutStaticCostSheetFields.close
| ...
| <-- first try
| <-- second try
| <-- third try
| <-- fourth try
| I see no values. Any ideas? Am I using the wrong kind of cursor to
| access the access database?
|
| Thanks in advance for your help.
| Greg.
|
| "Sometimes we need to kick at the darkness till it bleeds daylight"



Re: getting autonumber value when using addnew by Greg

Greg
Thu Sep 18 23:16:11 CDT 2003

Perfect! Thankyou so much

It appears that with the adOpenKeyset cursor this kind of check is
possible. I'm thankful that I don't have to rewrite my code :-)

Here are the results using the same checking code.
248<-- first try
248<-- second try
248<-- third try
248<-- fourth try

Take care
Greg.

Walter Zackery wrote:
> Try changing the 3rd parameter of the open method from 2 (adOpenDynamic) to
> 1 (adOpenKeyset) and see if that helps. Not all (if any) Jet versions
> support ADO's adOpenDynamic cursor. Depending on other factors, you may get
> either a static or dynamic cursor when using adOpenDynamic.
>
> "Greg" <gregmckone@yahoo.com> wrote in message
> news:3816e6d1.0309180701.3d7eb69b@posting.google.com...
> | Here is what I'm trying to do...
> |
> | Open a recordset (the code is more complex this is only one possible
> | path)
> | if it is an empty recordset then add a new record, and put values in
> | that record, update that record, and finally grab the autonumber value
> | for use in the next block of code.
> |
> | 'OPEN db
> |
> | Set objConn = Server.CreateObject("ADODB.Connection")
> | path = server.MapPath("TCSDB.mdb")
> | objConn.Open = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" &
> | path
> | 'set up recordset
> |
> | set rsPutStaticCostSheetFields =
> | server.createobject("adodb.recordset")
> | strSQL = "select * from CostSheets"
> | rsPutStaticCostSheetFields.open strSQL, objConn, 2, 2
> | 'oh its a new record. recordset has correct table / columns open
> |
> | rsPutStaticCostSheetFields.addNew
> | 'add new column values
> |
> | rsPutStaticCostSheetFields.update
> | 'TRY TO GET AUTONUMBER FIELD (FIRST COLUMN CALLED "CostSheetID")
> |
> | tmpCostSheetID = rsPutStaticCostSheetFields("CostSheetID")
> | response.write(tmpCostSheetID&"<-- first try<br>")
> | tmpCostSheetID = rsPutStaticCostSheetFields.Fields.Item("CostSheetID")
> | response.write(tmpCostSheetID&"<-- second try<br>")
> | tmpCostSheetID = rsPutStaticCostSheetFields(0)
> | response.write(tmpCostSheetID&"<-- third try<br>")
> | tmpCostSheetID = rsPutStaticCostSheetFields("CostSheetID").value
> | response.write(tmpCostSheetID&"<-- fourth try<br>")
> | rsPutStaticCostSheetFields.close
> | ...
> | <-- first try
> | <-- second try
> | <-- third try
> | <-- fourth try
> | I see no values. Any ideas? Am I using the wrong kind of cursor to
> | access the access database?
> |
> | Thanks in advance for your help.
> | Greg.
> |
> | "Sometimes we need to kick at the darkness till it bleeds daylight"
>
>


Re: getting autonumber value when using addnew by Greg

Greg
Thu Sep 18 23:17:25 CDT 2003

Great, Thanks.

Combining the information you directed me to with the information
provided by Walter (also in this thread), I was able to change the
cursor type and get the information I needed. The code I provided
produced this result...

248<-- first try
248<-- second try
248<-- third try
248<-- fourth try

Take care
Greg.

Bob Barrows wrote:
> Greg wrote:
>
>>Here is what I'm trying to do...
>>
>>Open a recordset (the code is more complex this is only one possible
>>path)
>>if it is an empty recordset then add a new record, and put values in
>>that record, update that record, and finally grab the autonumber value
>>for use in the next block of code.
>>
>
> http://www.aspfaq.com/show.asp?id=2174
> Scroll down to the Access section
>
> HTH,
> Bob Barrows
>
>