I run the below to add a record to my main table.
Private Sub CmdATech_Click()
Dim rst As ADODB.Recordset
On Error GoTo err_label
Set rst = New ADODB.Recordset
rst.Open "techs", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
rst!LName = Me.LName
rst!FName = Me.FName
rst!Email_Address = Me.Email_Address
rst!FolderName = Me.FolderName
Set rst = Nothing
MsgBox "New record created sucessfully", vbInformation, "Record created"
Me.LName = Null
Me.FName = Null
Me.Email_Address = Null
Me.FolderName = Null
MsgBox "Error creating new record" & vbNewLine & Err.Description, vbCritical, "Error creating new record"
' this sub requery's the combobox to add the new tech to the list of techs
' this also works fine
Private Sub cmdCForm_LostFocus()
Forms![techs]![cmbID] = Null
Forms!techs!txtHLink.Text = ""
This works and once the record has been added the primary key is assigned.
when I try to select the new "ID" (which is the primary key) the query returns nothing. in my frustration I deleted the code I had written.
Does anyone have a suggestion on how to get the primary key for the newly added record?
I figure I need to query the original table (the one with the primary key)