faqts : Computers : Programming : Languages : Asp : ASP/VBScript : Database Backed Sites : Microsoft Access

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

26 of 33 people (79%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How can I request the unique id key that MS Access generates in an autonumber field as it adds the new record

Feb 2nd, 2001 01:36
Acebone, Spy,


You will need the file adovbs.asp. 
This file defines a lot of ADODB constants. 
You can probably get it at http://www.microsoft.com.
Your ASP file may look something like this:
<!--#Include File="adovbs.asp"-->
<% 
'Create a database connection
Set dbConn = Server.CreateObject("ADODB.Connection")
dbConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\PATH\TO\YOUR\DATABASE\database.mdb"	
'Create a recordset object
Set rsNt = Server.CreateObject("ADODB.Recordset")
with rsNt
	'this line uses the constants
	'If you don't wanna go find adovbs.asp then you can use this line:
	'.Open "name_of_your_table", dbconn, 1, 2
	.Open "name_of_your_table", dbconn, adOpenKeyset,adLockPessimistic
	.AddNew
	'defining some data
	.Fields("name_of_a_field") = "a value"
	.Fields("name_of_another_field") = "another value"
	.Update
	NewID = .Fields("name_of_your_autoincrement_field")
end with
'closing the connection
dbConn.close
%>



© 1999-2004 Synop Pty Ltd