As usual – a dumb question that I’m hoping has an easy answer.
I have a main form which has an ‘add new qualification’ button which executes my form using
DoCmd.OpenForm “fmaddqualification”, acNormal, , , acFormAdd
I have a click event on this form which attempts to do some integrity checks and discard the field changes for the record update. Sadly, it seems to add a record even where I’ve detected it is a duplicate.
Any suggestions on the correct approach?
Private Sub Save_Click()
Dim Qual
Dim I As Long
If IsNull(Me.Institutions.Value) Or _
IsNull(Me.QualificationDescription.Value) Or _
IsNull(Me.QualificationTypeID.Value) Then
MsgBox “All fields are required to be entered”
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acDelete, , acMenuVer70
DoCmd.Close acForm, Me.Name, acSaveNo
Exit Sub
End If
For I = 0 To Forms!fmQualificationMain.Qualifications.ListCount – 1
Qual = Forms!fmQualificationMain.Qualifications.ItemData(I)
If Qual = Me.QualificationDescription.Value Then
MsgBox Me.QualificationDescription & ” already exists”, , “Qualification not added”
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acDelete, , acMenuVer70 ‘ <—– —- this doesn’t seem to work —- nor anything else I try
DoCmd.Close acForm, Me.Name, acSaveNo
Exit Sub
End If
Next I
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close acForm, Me.Name, acSaveNo
Exit_Save_Click:
Exit Sub
Err_Save_Click:
MsgBox Err.Description
Resume Exit_Save_Click
End Sub