I am trying to access the autonumber primary key of the newly created records through code. The datasourse is an access table.
The code was working fine when I used a connectionstring using AppConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\HECP.mdb;Persist Security Info=False"
Now that I am using an ODBC connection in my connectionstring such as
AppConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=HECPCon"
I am unable to located the autonumber primary key of the newly created record.
Below is the code I am using.
Dim cnNewHECP As New Connection
Dim rsNewHECP As New Recordset
Dim strNewHECPKey As String
cnNewHECP.Open AppConnectionString
rsNewHECP.Open "SELECT * FROM tblHECP WHERE 1=0", cnNewHECP, adOpenStatic, adLockOptimistic
With rsNewHECP
.AddNew
.Fields("CreateDate") = Now
.Fields("CreatedByID") = CurrUser.USER_PK
.Fields("RefNumber") = strRefNo
.Fields("EquipmentNoRefID") = txtEquip1.Tag
.Fields("LastAuditDate") = Now()
.Fields("LastAuditedByID") = CurrUser.USER_PK
.Fields("LastRevisionDate") = Now()
.Fields("LastRevisedByID") = CurrUser.USER_PK
.Update
strNewHECPKey = .Fields("HECPID")----> empty when step through
End With
Any help will be greatly appreciated
Thank you
ParyGoal
The code was working fine when I used a connectionstring using AppConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\HECP.mdb;Persist Security Info=False"
Now that I am using an ODBC connection in my connectionstring such as
AppConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=HECPCon"
I am unable to located the autonumber primary key of the newly created record.
Below is the code I am using.
Dim cnNewHECP As New Connection
Dim rsNewHECP As New Recordset
Dim strNewHECPKey As String
cnNewHECP.Open AppConnectionString
rsNewHECP.Open "SELECT * FROM tblHECP WHERE 1=0", cnNewHECP, adOpenStatic, adLockOptimistic
With rsNewHECP
.AddNew
.Fields("CreateDate") = Now
.Fields("CreatedByID") = CurrUser.USER_PK
.Fields("RefNumber") = strRefNo
.Fields("EquipmentNoRefID") = txtEquip1.Tag
.Fields("LastAuditDate") = Now()
.Fields("LastAuditedByID") = CurrUser.USER_PK
.Fields("LastRevisionDate") = Now()
.Fields("LastRevisedByID") = CurrUser.USER_PK
.Update
strNewHECPKey = .Fields("HECPID")----> empty when step through
End With
Any help will be greatly appreciated
Thank you
ParyGoal