Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access autonumber update.

Status
Not open for further replies.

macr0

Programmer
Jan 29, 2000
31
US
What's wrong with this code?

objRS.Open "InvLists", objConn, adOpenStatic, adLockOptimistic, adCmdTable
With objRS
.AddNew
.Fields("Name") = strName
.Fields("DateAdded") = Now
.Update
End With
iListID = objRS("ListID")

ListID is an autoNumer field in Access 2002, but it ends up being blank. If I .Requery it comes out to the first record in the table. I've seen a way to do this somewhere in the back of mind. I'm pretty sure you don't have to go back out to the database with another SELECT statement.

Any help appreciated,
Jeremy Lowery
 
Err,
I think you just leave it blank and it updates automatically you don't need to specify it.
 
Do you mean the ListID? Yeah, it does automatiically assign it. That is why I need to get it after I update the record ;)

Jeremy Lowery
 
Oh,
I get what u mean, you want to displasy the id after you have updated it without re-pulling it from the database?
 
But,
you must have had the id in the first place to hav entered the save page, eg. save.asp?id=65 ?? so you can just display it from that

<% =id %>

I hope this helps.

Regards
Big Dave
 
No,
This page is called &quot;CreateList.asp&quot; Self submiting form page.
 
Right,
Let me get it stratight, are you updating a record or creating a new record?
 
This code works :


dim rs, data_source, con, strID

data_source = &quot;Provider=Microsoft.Jet.OLEDB.4.0; Data Source=&quot; & Server.MapPath(&quot;admin.mdb&quot;)

Set con = Server.CreateObject(&quot;ADODB.Connection&quot;)
con.Open data_source
set rs = server.createobject(&quot;adodb.recordset&quot;)
rs.open &quot;t_news&quot;, con, 2, 2

rs.addnew

title = Request.Form(&quot;title&quot;)
if title=&quot;&quot; THEN
rs(&quot;title&quot;) = NULL
Else
rs(&quot;title&quot;) = title
END IF

datea = Request.Form(&quot;date&quot;)
if datea=&quot;&quot; THEN
rs(&quot;date&quot;) = NULL
Else
rs(&quot;date&quot;) = datea
END IF

rs.update
rs.movelast
strID = rs(&quot;id&quot;)

set rs = nothing
set con = nothing

Response.Write &quot;the list id for your entry is : &quot; & strID

Regards

Big Dave
 
Thanks a bunch dave, That's what I needed.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top