abenitez77
Board Regular
- Joined
- Dec 30, 2004
- Messages
- 149
I am not able to get values into a recordset. The first sql command to insert the records work, but when i try to retrieve the Max(ID), the recordset is Empty.
Dim rst2 As DAO.Recordset
Set Connection2 = CreateObject("ADODB.Connection")
sServer = "SAS01SRVSQ01\SASDATA"
sDBName = "UNFI_Temp"
ConnectionString = _
"Provider=SQLOLEDB;" & _
"Data Source=" + sServer + ";" & _
"Initial Catalog=" + sDBName + ";" & _
"Integrated Security=SSPI"
Connection2.Open ConnectionString
'Insert Header info into XlsData
tSQL = "Insert into XLSData (SupplierName, SupplierNumber, BuyDateS, ShipDateS, FilePath, FileName) "
tSQL = tSQL & "VALUES ('" & Supplier & "','" & SupplierNo & "','" & BuyDate & "','" & ShipDate & "','" & xFilePath & "','" & xFileName & "') "
Set rst2 = Connection2.Execute(tSQL)
rst2.MoveLast
rst2.MoveFirst
tSQL = "Select Max(ID) as IDMax From XLSData"
Set rst2 = Connection2.Execute(tSQL)
rst2.MoveLast
rst2.MoveFirst
myID = rst2.IDMax
Dim rst2 As DAO.Recordset
Set Connection2 = CreateObject("ADODB.Connection")
sServer = "SAS01SRVSQ01\SASDATA"
sDBName = "UNFI_Temp"
ConnectionString = _
"Provider=SQLOLEDB;" & _
"Data Source=" + sServer + ";" & _
"Initial Catalog=" + sDBName + ";" & _
"Integrated Security=SSPI"
Connection2.Open ConnectionString
'Insert Header info into XlsData
tSQL = "Insert into XLSData (SupplierName, SupplierNumber, BuyDateS, ShipDateS, FilePath, FileName) "
tSQL = tSQL & "VALUES ('" & Supplier & "','" & SupplierNo & "','" & BuyDate & "','" & ShipDate & "','" & xFilePath & "','" & xFileName & "') "
Set rst2 = Connection2.Execute(tSQL)
rst2.MoveLast
rst2.MoveFirst
tSQL = "Select Max(ID) as IDMax From XLSData"
Set rst2 = Connection2.Execute(tSQL)
rst2.MoveLast
rst2.MoveFirst
myID = rst2.IDMax