When I add a record to the table in an Access Database, I need to return the value of the AutoNumber (Unique ID) of the record (so that I can use the number to create a folder with the unique ID appended to the end of the folder name.
I'm using the following code to add records to the database. How can I retrieve the Unique ID after I have inserted a new record?
**********************************************************
Dim adoCon 'Holds the Database Connection Object
Dim rsAddEntry 'Holds the recordset for the record to be added
Dim strSQL 'Holds the SQL query to query the database
Set adoCon = Server.CreateObject("ADODB.Connection"
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath ("data/Licensee" & Session("cid" & "/companies.mdb"
Set rsAddEntry = Server.CreateObject("ADODB.Recordset"
strSQL = "SELECT * FROM tblCompanies;"
rsAddEntry.CursorType = 2
rsAddEntry.LockType = 3
rsAddEntry.Open strSQL, adoCon
rsAddEntry.AddNew
rsAddEntry.Fields("longName" = Request.Form("txtFull"
rsAddEntry.Fields("shortName" = Request.Form("txtShort"
rsAddEntry.Fields("addr1" = Request.Form("addrLn1"
rsAddEntry.Fields("addr2" = Request.Form("addrLn2"
rsAddEntry.Fields("addr3" = Request.Form("addrLn3"
rsAddEntry.Fields("city" = Request.Form("city"
rsAddEntry.Fields("state" = Request.Form("state"
rsAddEntry.Fields("zip" = Request.Form("zip"
rsAddEntry.Fields("alias1" = Request.Form("alt1"
rsAddEntry.Fields("alias2" = Request.Form("alt2"
rsAddEntry.Fields("alias3" = Request.Form("alt3"
rsAddEntry.Fields("alias4" = Request.Form("alt4"
rsAddEntry.Fields("alias5" = Request.Form("alt5"
rsUpdateEntry.Fields("coURL" = Request.Form("txtURL"
rsAddEntry.Update
rsAddEntry.Close
Set rsAddEntry = Nothing
Set adoCon = Nothing
' Copy folder with database to new folder for new company
folderPath = Server.MapPath("data/Licensee" & Session("cid" & "/company" & AUTONUM & "/"
fromPath = Server.MapPath("Tmp/"
Set fsObj = CreateObject("Scripting.FileSystemObject"
If fsObj.FolderExists(fromPath) Then
set fo = fsObj.GetFolder(fromPath)
' The following line is where it dies
fo.Copy folderPath, false
set fo=nothing
set fsObj=nothing
msg = "Copied folder"
End If
I'm using the following code to add records to the database. How can I retrieve the Unique ID after I have inserted a new record?
**********************************************************
Dim adoCon 'Holds the Database Connection Object
Dim rsAddEntry 'Holds the recordset for the record to be added
Dim strSQL 'Holds the SQL query to query the database
Set adoCon = Server.CreateObject("ADODB.Connection"
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath ("data/Licensee" & Session("cid" & "/companies.mdb"
Set rsAddEntry = Server.CreateObject("ADODB.Recordset"
strSQL = "SELECT * FROM tblCompanies;"
rsAddEntry.CursorType = 2
rsAddEntry.LockType = 3
rsAddEntry.Open strSQL, adoCon
rsAddEntry.AddNew
rsAddEntry.Fields("longName" = Request.Form("txtFull"
rsAddEntry.Fields("shortName" = Request.Form("txtShort"
rsAddEntry.Fields("addr1" = Request.Form("addrLn1"
rsAddEntry.Fields("addr2" = Request.Form("addrLn2"
rsAddEntry.Fields("addr3" = Request.Form("addrLn3"
rsAddEntry.Fields("city" = Request.Form("city"
rsAddEntry.Fields("state" = Request.Form("state"
rsAddEntry.Fields("zip" = Request.Form("zip"
rsAddEntry.Fields("alias1" = Request.Form("alt1"
rsAddEntry.Fields("alias2" = Request.Form("alt2"
rsAddEntry.Fields("alias3" = Request.Form("alt3"
rsAddEntry.Fields("alias4" = Request.Form("alt4"
rsAddEntry.Fields("alias5" = Request.Form("alt5"
rsUpdateEntry.Fields("coURL" = Request.Form("txtURL"
rsAddEntry.Update
rsAddEntry.Close
Set rsAddEntry = Nothing
Set adoCon = Nothing
' Copy folder with database to new folder for new company
folderPath = Server.MapPath("data/Licensee" & Session("cid" & "/company" & AUTONUM & "/"
fromPath = Server.MapPath("Tmp/"
Set fsObj = CreateObject("Scripting.FileSystemObject"
If fsObj.FolderExists(fromPath) Then
set fo = fsObj.GetFolder(fromPath)
' The following line is where it dies
fo.Copy folderPath, false
set fo=nothing
set fsObj=nothing
msg = "Copied folder"
End If