Hi all,
I am doing an insert into an Access table, and then trying to fetch the ID
of the record that was just inserted. But my code is not able to detect the
record just inserted. Could someone please help?
TIA,
Sheila
My code is:
'first insert the new record into tblEmployee
'---------------------------------------------------------------------
ssql = " INSERT INTO tblEmployee " & _
" ( " & _
" emp_first ," & _
" emp_last " & _
" ) " & _
" VALUES ('" & strFirst & "', " & _
" '" & strLast & "') "
Set objRecSet = ExecuteSQL(ssql)
'-------------------------------------------------------------------
'the previous insertion generated a new emp_id so we can now get it...
'-------------------------------------------------------------------
ssql = "SELECT emp_id " & _
"FROM tblEmployee " & _
"WHERE emp_first = '" & strFirst & "' " & _
"AND emp_last = '" & strLast & "' "
Set objRecSet = ExecuteSQL(ssql)
if (NOT objRecSet.BOF) AND (NOT objRecSet.EOF) Then
intEmpID = objRecSet("emp_id"
'****It never gets here! ****
Response.Write "intEmpID= " & intEmpID
end if
I am doing an insert into an Access table, and then trying to fetch the ID
of the record that was just inserted. But my code is not able to detect the
record just inserted. Could someone please help?
TIA,
Sheila
My code is:
'first insert the new record into tblEmployee
'---------------------------------------------------------------------
ssql = " INSERT INTO tblEmployee " & _
" ( " & _
" emp_first ," & _
" emp_last " & _
" ) " & _
" VALUES ('" & strFirst & "', " & _
" '" & strLast & "') "
Set objRecSet = ExecuteSQL(ssql)
'-------------------------------------------------------------------
'the previous insertion generated a new emp_id so we can now get it...
'-------------------------------------------------------------------
ssql = "SELECT emp_id " & _
"FROM tblEmployee " & _
"WHERE emp_first = '" & strFirst & "' " & _
"AND emp_last = '" & strLast & "' "
Set objRecSet = ExecuteSQL(ssql)
if (NOT objRecSet.BOF) AND (NOT objRecSet.EOF) Then
intEmpID = objRecSet("emp_id"
Response.Write "intEmpID= " & intEmpID
end if