I
Iram
Hello,
I have a "Save and Close" button on a form that is supposed to verify that
13 fields have been filled out befoe closing the data entry form (below is in
the On Click Event Procedure. The problem is that the code doesn't work like
its supposed to some times. For instance if I enter data into 10 of the
fields and click "Save and Close" I get a prompt for each of the fields that
I did not fill in and at the same time it tabs through each of them like its
supposed to HOWEVER if I just fill in one of the remaining 3 fields (leaving
2 fields blank) I get two prompts and after clicking Ok to both of them then
the form closes without giving me a chance to add data to those fields. Why
doesn't it let me add data before closing the form? Can you help me fix this?
I am using Access 2003.
Private Sub Save_and_Close_Click()
Dim frm As Form
Dim strMsgBoxTitle As String
Set frm = Forms!frmQuestionnaireAdd!
strMsgBoxTitle = "Mandatory Field"
' Check mandatory field Calwin Number
If IsNull(frm.CalwinNumb.Value) Then
MsgBox "Please fill in the Calwin Number field.", vbOKOnly,
strMsgBoxTitle
frm.CalwinNumb.SetFocus
End If
' Check mandatory Multiple referrals
If IsNull(frm.MultipleRfrrl_YN.Value) Then
MsgBox "Please select Yes or No for multiple referrals.", vbOKOnly,
strMsgBoxTitle
frm.MultipleRfrrl_YN.SetFocus
End If
' Check mandatory field CP First Name
If IsNull(frm.CP_NameF.Value) Then
MsgBox "Please fill in the CP's First Name.", vbOKOnly, strMsgBoxTitle
frm.CP_NameF.SetFocus
End If
' Check mandatory field CP Last Name
If IsNull(frm.CP_NameL.Value) Then
MsgBox "Please fill in the CP's Last Name.", vbOKOnly, strMsgBoxTitle
frm.CP_NameL.SetFocus
End If
' Check mandatory field CP Address Line 1
If IsNull(frm.CP_AddLine1.Value) Then
MsgBox "Please fill in the CP's Address Line 1.", vbOKOnly,
strMsgBoxTitle
frm.CP_AddLine1.SetFocus
End If
' Check mandatory field CP's City
If IsNull(frm.CP_AddCity.Value) Then
MsgBox "Please fill in the CP's City.", vbOKOnly, strMsgBoxTitle
frm.CP_AddCity.SetFocus
End If
' Check mandatory field CP's State
If IsNull(frm.CP_AddState.Value) Then
MsgBox "Please fill in the CP's State.", vbOKOnly, strMsgBoxTitle
frm.CP_AddState.SetFocus
End If
' Check mandatory field CP's zip
If IsNull(frm.CP_AddZip.Value) Then
MsgBox "Please fill in the CP's zip code.", vbOKOnly, strMsgBoxTitle
frm.CP_AddZip.SetFocus
End If
' Check mandatory field NCP's First Name
If IsNull(frm.NP_NameF.Value) Then
MsgBox "Please fill in the NCP's First Name.", vbOKOnly,
strMsgBoxTitle
frm.NP_NameF.SetFocus
End If
' Check mandatory field NCP's Last Name
If IsNull(frm.NP_NameL.Value) Then
MsgBox "Please fill in the NCP's Last Name.", vbOKOnly, strMsgBoxTitle
frm.NP_NameL.SetFocus
End If
' Check mandatory field Children of this relationship
If IsNull(frm.ChildrenOfThisRelationship.Value) Then
MsgBox "Please fill in the Children of this relationship info.",
vbOKOnly, strMsgBoxTitle
frm.ChildrenOfThisRelationship.SetFocus
End If
' Check mandatory field Interview Notes
If IsNull(frm.InterviewNotes.Value) Then
MsgBox "Please fill in the Interview Notes.", vbOKOnly, strMsgBoxTitle
Me.InterviewNotes.SetFocus
Else
DoCmd.Close
End If
End Sub
I have a "Save and Close" button on a form that is supposed to verify that
13 fields have been filled out befoe closing the data entry form (below is in
the On Click Event Procedure. The problem is that the code doesn't work like
its supposed to some times. For instance if I enter data into 10 of the
fields and click "Save and Close" I get a prompt for each of the fields that
I did not fill in and at the same time it tabs through each of them like its
supposed to HOWEVER if I just fill in one of the remaining 3 fields (leaving
2 fields blank) I get two prompts and after clicking Ok to both of them then
the form closes without giving me a chance to add data to those fields. Why
doesn't it let me add data before closing the form? Can you help me fix this?
I am using Access 2003.
Private Sub Save_and_Close_Click()
Dim frm As Form
Dim strMsgBoxTitle As String
Set frm = Forms!frmQuestionnaireAdd!
strMsgBoxTitle = "Mandatory Field"
' Check mandatory field Calwin Number
If IsNull(frm.CalwinNumb.Value) Then
MsgBox "Please fill in the Calwin Number field.", vbOKOnly,
strMsgBoxTitle
frm.CalwinNumb.SetFocus
End If
' Check mandatory Multiple referrals
If IsNull(frm.MultipleRfrrl_YN.Value) Then
MsgBox "Please select Yes or No for multiple referrals.", vbOKOnly,
strMsgBoxTitle
frm.MultipleRfrrl_YN.SetFocus
End If
' Check mandatory field CP First Name
If IsNull(frm.CP_NameF.Value) Then
MsgBox "Please fill in the CP's First Name.", vbOKOnly, strMsgBoxTitle
frm.CP_NameF.SetFocus
End If
' Check mandatory field CP Last Name
If IsNull(frm.CP_NameL.Value) Then
MsgBox "Please fill in the CP's Last Name.", vbOKOnly, strMsgBoxTitle
frm.CP_NameL.SetFocus
End If
' Check mandatory field CP Address Line 1
If IsNull(frm.CP_AddLine1.Value) Then
MsgBox "Please fill in the CP's Address Line 1.", vbOKOnly,
strMsgBoxTitle
frm.CP_AddLine1.SetFocus
End If
' Check mandatory field CP's City
If IsNull(frm.CP_AddCity.Value) Then
MsgBox "Please fill in the CP's City.", vbOKOnly, strMsgBoxTitle
frm.CP_AddCity.SetFocus
End If
' Check mandatory field CP's State
If IsNull(frm.CP_AddState.Value) Then
MsgBox "Please fill in the CP's State.", vbOKOnly, strMsgBoxTitle
frm.CP_AddState.SetFocus
End If
' Check mandatory field CP's zip
If IsNull(frm.CP_AddZip.Value) Then
MsgBox "Please fill in the CP's zip code.", vbOKOnly, strMsgBoxTitle
frm.CP_AddZip.SetFocus
End If
' Check mandatory field NCP's First Name
If IsNull(frm.NP_NameF.Value) Then
MsgBox "Please fill in the NCP's First Name.", vbOKOnly,
strMsgBoxTitle
frm.NP_NameF.SetFocus
End If
' Check mandatory field NCP's Last Name
If IsNull(frm.NP_NameL.Value) Then
MsgBox "Please fill in the NCP's Last Name.", vbOKOnly, strMsgBoxTitle
frm.NP_NameL.SetFocus
End If
' Check mandatory field Children of this relationship
If IsNull(frm.ChildrenOfThisRelationship.Value) Then
MsgBox "Please fill in the Children of this relationship info.",
vbOKOnly, strMsgBoxTitle
frm.ChildrenOfThisRelationship.SetFocus
End If
' Check mandatory field Interview Notes
If IsNull(frm.InterviewNotes.Value) Then
MsgBox "Please fill in the Interview Notes.", vbOKOnly, strMsgBoxTitle
Me.InterviewNotes.SetFocus
Else
DoCmd.Close
End If
End Sub