- Code: Select all
Private Sub cmdAdd_Click()
Dim lngGraduateID As Long
Dim sql As String
Dim stDocName As String
Dim stLinkCriteria As String
On Error GoTo sbGAP_Error
stDocName = "frmGAP"
sql = "INSERT INTO tblGAP (GraduateID) Values (" & GraduateID & ")"
stLinkCriteria = "[GraduateID]=" & Me![GraduateID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
If Err.Number = 3022 Then
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Add Graduate "
However, when I click the button, at first it opens the correct Form, but the Graduate field is blank. But if I click the button again, it opens the Form, and this time it has populated the 'Graduate' field with the FK that was inserted via the SQL Command.
I tried to do a Refresh and/or Requery to force Access to update the Table, but it produced a error. I then tried to close the Form, hoping it would force the Refresh, but then it failed to open the form because it couldn't match the ID Fields.
Is there a way to get Access to Insert this new Record into the Table and then open the Form based on this Table with the new Data populated?
Many thanks in advance for any help.