Hans kindly gave me some code to use on my Access Database, but the SQL element stopped working today. :(
The User creates a form and then clicks a button, which fires the Event.
The Event is supposed to insert the values of the form that's just been completed into the Database and then open a different new Form that contains the values that have just been inserted.
The Code does include an Error option, but no error comes up. All that happens is that the New Form opens, but it's blank as no data has been inserted.
Therefore, it looks like the SQL element is no longer working, but the rest of the code is.
Any thoughts why this would have just stopped?
Thanks for any help.
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 sbCreateReviews_Error
' ***** Save the record if necessary *****
If Me.Dirty Then Me.Dirty = False
sql = "INSERT INTO tblGAP (GraduateID, GAPstaff_FK, LC, ReferralDate) Values (" & GraduateID & _
", " & GAPstaff_FK & ", " & LC & ", #" & Format(ReferralDate, "yyyy/mm/dd") & "#)"
CurrentDb.Execute sql
stDocName = "frmGAP"
stLinkCriteria = "[GraduateID]=" & Me![GraduateID]
DoEvents
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit Sub
sbCreateReviews_Error:
If Err.Number = 3022 Then
Resume Next
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Add Graduate "
End If
End Sub