Hi All
I have been looking around for help, and finally post this problem.
I created a form to edit a record. Before i can click save button on the edit form i need to check if the data that have been edit exists in the table. But if i m calling the same record and updating the same record without changing anything it should allowed to save.
Example: I m creating a table to save all types of courses (course_id, course_code, course_description)
On the Edit Course form, when click Save button, in the code screen i check for
(1) Is null (incase the user try to erase the value in course_code and try to save a blank code.
(2) Next i need to check if the new code is exists in the table, if exits do not allow to save reminder that duplicate code.
(3) If the code is same, which mean if i change the course description, it should allow to save.
My Code:
Private Sub btnSave_Click()
On Error GoTo Err_btnSave_Click
Dim criteria As String
criteria = "[course_code] = '" & Me.course_code.Value & "'"
' Comments: Checking all the fields are mandatory during creation of Course.
If IsNull(Me![course_code]) Then
MsgBox "Mandatory Field: Course Code."
ElseIf DCount("course_code", "s_courses", _
criteria) > 0 Then
'Undo duplicate entry
Me.Undo
'Message box warning of duplication
MsgBox "Duplicate code."
ElseIf IsNull(Me![course_name]) Then
MsgBox "Mandatory Field: Course Name."
Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close
End If
Exit_btnSave_Click:
Exit Sub
Err_btnSave_Click:
MsgBox Err.description
Resume Exit_btnSave_Click
End Sub
Please help.
Gurmet