Getting the last auto number of a record added in MS Access

Getting the last auto number of a record added in MS Access

am 11.07.2005 17:55:02 von fahadoman

I have a form where I would like to Getting the last auto of a record added
in MS Access in Windows 2000 Server using DNS connect method for connecting
to the Database

I had tried to use

objRS.Fields.Item("company_id").Value

objRS("company_id")

CStr(objRS("company_id"))

It really made me crazy because it gives me an empty auto number. What is
the problem?

HELP ME PLZZZZ

Below you will find the whole code


<%

Dim conn
Set conn = Server.CreateObject("ADODB.Connection")
conn.mode=3
conn.Open "DSN=formsdb"

DIM objRS, UrlStr, objRSregisteration








Set objRS = Server.CreateObject("ADODB.Recordset")
Set objRStestadding = Server.CreateObject("ADODB.Recordset")




objRS.CursorType = 2
objRS.LockType = 3
objRS.Open "company", conn,,,adcmdtable



objRS.AddNew




objRS("language_interface") = fixQuotes(request.form("language_interface"))

objRS("name_of_applicant") = fixQuotes(request.form("name_of_applicant"))

objRS("office_number") = fixQuotes(request.form("office_number"))

objRS("e_mail") = fixQuotes(request.form("e_mail"))
objRS("user_name") = fixQuotes(request.form("e_mail"))

objRS("identification_type") = fixQuotes(request.form("identification_type"))

objRS("identification_number") =
fixQuotes(request.form("identification_number"))


objRS("town_postel_office") = fixQuotes(request.form("town_postel_office"))

objRS("building_no") = fixQuotes(request.form("building_no"))

objRS("floor_no") = fixQuotes(request.form("floor_no"))

objRS("postel_code") = fixQuotes(request.form("postel_code"))

objRS("street_name") = fixQuotes(request.form("street_name"))



objRS("contact_person") = fixQuotes(request.form("contact_person"))

objRS("contact_tel") = fixQuotes(request.form("contact_tel"))

objRS("contact_e_mail") = fixQuotes(request.form("contact_e_mail"))

objRS("contact_job") = fixQuotes(request.form("contact_job"))

objRS("p_o_box") = fixQuotes(request.form("p_o_box"))

objRS("fax_number") = fixQuotes(request.form("fax_number"))

objRS("website") = fixQuotes(request.form("website"))


objRS("catgory_business") = fixQuotes(request.form("catgory_business"))

objRS("application_date") = date()

objRS("reg_status") = "waiting"
objRS("num_emp_applying") = request.form("num_emp_applying")

objRS("sector") = request.form("sector")

objRS.Update
dim contact_person, intID, e_mail

intID = objRS.Fields.Item("company_id").Value
e_mail = objRS.Fields.Item("e_mail").Value
response.write("
here please ->" & CStr(objRS("company_id")) & "
test" & CStr(intID) & "here please" & CStr(objRS.Fields.Item(1).Value))
response.write("
" & e_mail)

Re: Getting the last auto number of a record added in MS Access

am 11.07.2005 19:22:25 von unknown

Hi fahadoman,

Take a look here: http://www.aspfaq.com/show.asp?id=2174

Ray at work

"fahadoman" wrote in message
news:17FF3F57-1CE2-427D-B861-399F94E77248@microsoft.com...
> I have a form where I would like to Getting the last auto of a record
added
> in MS Access in Windows 2000 Server using DNS connect method for
connecting
> to the Database
>
> I had tried to use
>
> objRS.Fields.Item("company_id").Value
>
> objRS("company_id")
>
> CStr(objRS("company_id"))
>
> It really made me crazy because it gives me an empty auto number. What is
> the problem?
>
> HELP ME PLZZZZ
>
> Below you will find the whole code
>
>
> <%

Re: Getting the last auto number of a record added in MS Access

am 11.07.2005 19:56:05 von JitGanguly

There are two ways, depending on your Access version (2k or before):

The standard way (appears to be difficult first but is quite easy once
you've been getting used to it):
HOWTO: Return Record's Autonumber Value Inserted into Access DB
http://support.microsoft.com/support/kb/articles/Q221/9/31.A SP

The new, simplified way,
INFO: Jet OLE DB Provider Version 4.0 Supports SELECT @@Identity
http://support.microsoft.com/support/kb/articles/Q232/1/44.A SP

Please tell me which way is right for you, and ask if you should be running
into any problem.

"Ray Costanzo [MVP]" wrote:

> Hi fahadoman,
>
> Take a look here: http://www.aspfaq.com/show.asp?id=2174
>
> Ray at work
>
> "fahadoman" wrote in message
> news:17FF3F57-1CE2-427D-B861-399F94E77248@microsoft.com...
> > I have a form where I would like to Getting the last auto of a record
> added
> > in MS Access in Windows 2000 Server using DNS connect method for
> connecting
> > to the Database
> >
> > I had tried to use
> >
> > objRS.Fields.Item("company_id").Value
> >
> > objRS("company_id")
> >
> > CStr(objRS("company_id"))
> >
> > It really made me crazy because it gives me an empty auto number. What is
> > the problem?
> >
> > HELP ME PLZZZZ
> >
> > Below you will find the whole code
> >
> >
> > <%
>
>
>

Re: Getting the last auto number of a record added in MS Access

am 15.07.2005 08:39:17 von Bullschmidt

Here's some sample code I use WHEN FIRST OPENING the recordset (notice
the CursorType):

' Open rs.
Set objRS = Server.CreateObject("ADODB.Recordset")
' (1=CursorType of adOpenKeyset in case ever want to get an
autonumber of new rec,
' 3=LockType of adLockOptimistic because updating.)
objRS.Open strSQL, objConn, 1, 3

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
http://www.Bullschmidt.com
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...


*** Sent via Developersdex http://www.developersdex.com ***