A
Associates
Hi,
I would like to perform data validation before the insertion of a new record
into the table in Access database.
So in the form, i have a few fields that need to be checked to see if they
are empty or entered. I have the following codes in the event of
"Form_BeforeUpdate"
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim mesg, Title As String
'Check if all the required fields are entered
If Me.Stud_ID <> "" Then
If Me.Department_ID <> "" Then
'warning message
mesg = "Data has been changed in this record. Do you want
to proceed?"
Title = "Warning !!!"
If MsgBox(mesg, vbYesNo, Title) = vbNo Then
'cancel the update action
Cancel = True
'undo all the data as well as the beforeupdate event
Me.Undo
End If
End If
End If
End Sub
This code behaves the way i want it to but still the record gets inserted
into the table even when the department_ID field is empty. This is not right.
How do i get around this problem from the form level?
Thank you in advance
I would like to perform data validation before the insertion of a new record
into the table in Access database.
So in the form, i have a few fields that need to be checked to see if they
are empty or entered. I have the following codes in the event of
"Form_BeforeUpdate"
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim mesg, Title As String
'Check if all the required fields are entered
If Me.Stud_ID <> "" Then
If Me.Department_ID <> "" Then
'warning message
mesg = "Data has been changed in this record. Do you want
to proceed?"
Title = "Warning !!!"
If MsgBox(mesg, vbYesNo, Title) = vbNo Then
'cancel the update action
Cancel = True
'undo all the data as well as the beforeupdate event
Me.Undo
End If
End If
End If
End Sub
This code behaves the way i want it to but still the record gets inserted
into the table even when the department_ID field is empty. This is not right.
How do i get around this problem from the form level?
Thank you in advance