help with validate else do something

R

richard harris

Hi,

i have found via this forum how to validate data on save using this line of
code

If IsNull([Forms]![frmIDD]![IDDFeeRefund]) Then
MsgBox "Fee Refund field not completed", vbInformation, "Need
information "
End If

what i cant seem to do is the following.

if all fields ahve been validated i need to 'task A' if not i need to exit
the sub until the fields have been validated then move on to 'Task A' by
clicking the proceed button again.

currently the programme is giving the correct propts for the missing data,
but then proceeds to Task A without allowing the user to enter the data.

i tried this code after the intitial checking of the data. can anyone help


If IsNull(([Forms]![frmIDD]![IDDMORT]) Or ([Forms]![frmIDD]![IDDLIFETIME])
Or ([Forms]![frmIDD]![IDDBTL]) Or ([Forms]![frmIDD]![IDDPureProtection]) _
Or ([Forms]![frmIDD]![IDDHomeIns]) Or ([Forms]![frmIDD]![IDDASU]) Or
([Forms]![frmIDD]![IDDMortBasis]) Or ([Forms]![frmIDD]![IDDLifeTimeBasis]) _
Or ([Forms]![frmIDD]![IDDPureProtectionBasis]) Or
([Forms]![frmIDD]![IDDHomeInsBasis]) Or ([Forms]![frmIDD]![IDDASUBasis]) _
Or ([Forms]![frmIDD]![IDDMortAdv]) Or ([Forms]![frmIDD]![IDDInsAdv]) Or
([Forms]![frmIDD]![IDDFeeBasis]) Or ([Forms]![frmIDD]![IDDFeeRefund])) Then

If vbYes = MsgBox("Have you issued the IDD to your client. ", vbYesNo +
vbInformation, _
"IDD Issued") Then
Me.IDDConfirmIssued = True
Me.IDDIssued = "Yes"
Me.IDDIssueDate.Visible = True
Me.IDDIssueDate = Date
DoCmd.Close acForm, "frmIDD", acSaveYes
Else
MsgBox "You can not proceed unless you issue the IDD. ", vbOKOnly +
vbwarning, _
"IDD not Issued"
Me.IDDConfirmIssued = False
Cancel = True
End If

greatly appreciated. richard
 
R

Rod Plastow

Richard,

You are obviously comfortable with coding so let me describe a technique I
often use when validating the data contained on a form.

The first step is to create a Function within the form module that I name
'Valid', e.g.

Private Function Valid() as Boolean
Valid = False
 
R

richard harris

Hi rod,

thanks for your help. perfect.

regards

richard

Rod Plastow said:
Richard,

You are obviously comfortable with coding so let me describe a technique I
often use when validating the data contained on a form.

The first step is to create a Function within the form module that I name
'Valid', e.g.

Private Function Valid() as Boolean
Valid = False
.
. insert validation tests here
.
Valid = True
End Function

Because the function is private it's 'seen' only by the module in which it
resides so you can have an identically named function in every form module.
Next step is to code each and every validation test inside this function.
Simple tests take the a structure similar to the following:

If IsNull(mycontrol) then
Msgbox "Tell user the error and what to do"
Me.mycontrol.setfocus
Exit function
End If

Note that each validation has: the test; a message if the test fails; a set
focus to position the user in the appropriate control; an immediate exit
(note that the return value of the function has been set to false at the
beginning of the procedure). Include as many such validation tests as are
necessary. If all tests are passed then the ultimate line of the procedure
sets the return value of the function to True.

OK, now in whatever event you need to check the data - usually Before Update
because you can cancel the event - all you need to code is:

If Not Me.Valid Then
'Take whatever action is necessary - usually a cancel or an immediate exit
of this code
End If

Trying to be a little more specific in your case:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not Me.Valid Then
Cancel = True
Exit Sub
End If
'Code to perform or invoke TaskA goes here
End Sub

Regards,

Rod

richard harris said:
Hi,

i have found via this forum how to validate data on save using this line of
code

If IsNull([Forms]![frmIDD]![IDDFeeRefund]) Then
MsgBox "Fee Refund field not completed", vbInformation, "Need
information "
End If

what i cant seem to do is the following.

if all fields ahve been validated i need to 'task A' if not i need to exit
the sub until the fields have been validated then move on to 'Task A' by
clicking the proceed button again.

currently the programme is giving the correct propts for the missing data,
but then proceeds to Task A without allowing the user to enter the data.

i tried this code after the intitial checking of the data. can anyone help


If IsNull(([Forms]![frmIDD]![IDDMORT]) Or ([Forms]![frmIDD]![IDDLIFETIME])
Or ([Forms]![frmIDD]![IDDBTL]) Or ([Forms]![frmIDD]![IDDPureProtection]) _
Or ([Forms]![frmIDD]![IDDHomeIns]) Or ([Forms]![frmIDD]![IDDASU]) Or
([Forms]![frmIDD]![IDDMortBasis]) Or ([Forms]![frmIDD]![IDDLifeTimeBasis]) _
Or ([Forms]![frmIDD]![IDDPureProtectionBasis]) Or
([Forms]![frmIDD]![IDDHomeInsBasis]) Or ([Forms]![frmIDD]![IDDASUBasis]) _
Or ([Forms]![frmIDD]![IDDMortAdv]) Or ([Forms]![frmIDD]![IDDInsAdv]) Or
([Forms]![frmIDD]![IDDFeeBasis]) Or ([Forms]![frmIDD]![IDDFeeRefund])) Then

If vbYes = MsgBox("Have you issued the IDD to your client. ", vbYesNo +
vbInformation, _
"IDD Issued") Then
Me.IDDConfirmIssued = True
Me.IDDIssued = "Yes"
Me.IDDIssueDate.Visible = True
Me.IDDIssueDate = Date
DoCmd.Close acForm, "frmIDD", acSaveYes
Else
MsgBox "You can not proceed unless you issue the IDD. ", vbOKOnly +
vbwarning, _
"IDD not Issued"
Me.IDDConfirmIssued = False
Cancel = True
End If

greatly appreciated. richard
 
Top