T
towdit
Hi,
I am using VBA to insert a new record in a table that has an autonumber as
the primary key. After the insert, I do dlookup on the table to retrieve the
primary key of the newly inserted record so that I can add it to a relation
table. However, the issue I am having is that when I do the lookup, it cannot
find the record in the table.
Here is a portion of the code I am using:
' Add the competency element entry to the tblCompetencyElement table.
Set db = CurrentDb()
strSQLQuery = "INSERT INTO tblCompetencyElement (Code, Name)
VALUES " & _
"('" & strStdNo & "', '" & strStdName & "')" & Chr(10)
Debug.Print strSQLQuery
Call db.Execute(strSQLQuery)
' Now get the unique id of the entry just added.
varX = DLookup("[CEID]", "tblCompetencyElement", "
I am using VBA to insert a new record in a table that has an autonumber as
the primary key. After the insert, I do dlookup on the table to retrieve the
primary key of the newly inserted record so that I can add it to a relation
table. However, the issue I am having is that when I do the lookup, it cannot
find the record in the table.
Here is a portion of the code I am using:
' Add the competency element entry to the tblCompetencyElement table.
Set db = CurrentDb()
strSQLQuery = "INSERT INTO tblCompetencyElement (Code, Name)
VALUES " & _
"('" & strStdNo & "', '" & strStdName & "')" & Chr(10)
Debug.Print strSQLQuery
Call db.Execute(strSQLQuery)
' Now get the unique id of the entry just added.
varX = DLookup("[CEID]", "tblCompetencyElement", "
Code:
= '" &
strStdNo & "' AND [Name] = '" & _
strStdName & "'")
Any suggestions?