Bit of help needed on Validation Function ElseIf

T

Tal

So, I have a big long function that validates all the data on an entry form.
However, I don't know how to put a Else that skips to the next line instead
of returning true. This only effects that last two items in my code. See
below.
Basically, the function works unless you haven't marked it as paid AND if
the donation is over $1000.00. Cause once you answer the paid/unpaid problem,
it marks it as True and skips the "Over $1000.00" issue.
Is there something I can put in there that validates the payment issue and
then continues on to the amount.

Many thanks in advance for all your help!!

Cheers,
Tal

Private Function fnValidateEntry() As Boolean
fnValidateEntry = False
If IsNull(Me.cboSelectDonor) Then
If MsgBox("You must select a donor. Click OK to complete the entry.
Click Cancel to continue without saving the record.", vbOKCancel, "Missing
Information") = vbOK Then
fnValidateEntry = False
Me.cboSelectDonor.SetFocus
Else
If Me.Dirty Then
Me.Undo
End If
End If
ElseIf IsNull(Me.cboDonorAddress) Then
If MsgBox("You must select a donor address. Click OK to complete the
entry. Click Cancel to continue without saving the record.", vbOKCancel,
"Missing Information") = vbOK Then
fnValidateEntry = False
Me.cboDonorAddress.SetFocus
Else
If Me.Dirty Then
Me.Undo
End If
End If
ElseIf IsNull(Me.dtDonationPaymentDate) Then
If MsgBox("Did you intend to mark this donation as paid. Click Yes to
return to the record. Click No to leave the donation unpaid.", vbYesNo,
"Payment Information") = vbYes Then
fnValidateEntry = False
Me.ynDonationPaid.SetFocus
Else
fnValidateEntry = True
End If
ElseIf Me.curDonationAmount >= 1000 Then
If MsgBox("This donation requires follow-up. Does it require any special
action? Click Yes to return to the record and enter the special actions in
the Comment field. Or click No to continue. A letter will be sent by
default.", vbYesNo, "Follow Up Required") = vbYes Then
fnValidateEntry = False
Me.memDonationComment.SetFocus
Else
fnValidateEntry = True
End If
Else
fnValidateEntry = True
End If
End Function
 
J

Jeanette Cunningham

Hi Tal,
Try it like this-->

Private Function fnValidateEntry() As Boolean
Dim bolPartValidate as Boolean
bolPartValidate = False
fnValidateEntry = False
If IsNull(Me.cboSelectDonor) Then
bolPartValidate = False
If MsgBox("You must select a donor. Click OK to complete the entry.
Click Cancel to continue without saving the record.", vbOKCancel, "Missing
Information") = vbOK Then
Me.cboSelectDonor.SetFocus
Else
If Me.Dirty Then
Me.Undo
End If
Else
bolPartValidate = True
End If

ElseIf IsNull(Me.cboDonorAddress) Then
bolPartValidate = False
If MsgBox("You must select a donor address. Click OK to complete the
entry. Click Cancel to continue without saving the record.", vbOKCancel,
"Missing Information") = vbOK Then
Me.cboDonorAddress.SetFocus
Else
If Me.Dirty Then
Me.Undo
End If
Else
bolPartValidate = True
End If

ElseIf IsNull(Me.dtDonationPaymentDate) Then
bolPartValidate = False
If MsgBox("Did you intend to mark this donation as paid. Click Yes to
return to the record. Click No to leave the donation unpaid.", vbYesNo,
"Payment Information") = vbYes Then
Me.ynDonationPaid.SetFocus
Else
End If
Else
bolPartValidate = True
End If

If bolPartValidate = True Then
If Me.curDonationAmount >= 1000 Then
If MsgBox("This donation requires follow-up. Does it require any special
action? Click Yes to return to the record and enter the special actions in
the Comment field. Or click No to continue. A letter will be sent by
default.", vbYesNo, "Follow Up Required") = vbYes Then
fnValidateEntry = True
Me.memDonationComment.SetFocus
Else
fnValidateEntry = True
End If
End If
End If
End Function



Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
T

Tal

Hi Jeanette,

Thank you so much for your reply.

I see where you are going with this, however, I think there must be some End
Ifs and Elses in the wrong place, cause I am getting Else without If error
messages.
Thoughts?

Again, thank you!!

Tal
 
D

Douglas J. Steele

Looks like

Else
If Me.Dirty Then
Me.Undo
End If
Else

should actually be

Else
If Me.Dirty Then
Me.Undo
End If
End If
Else
 
T

Tal

Hi!

Thanks for sticking with me.
I am still getting the Else without If error message.
When I do a debug, it seems to not like the ElseIf...
Also, it is stalling out at the last parameter (Donation Amount >=1000).
I am copying the current version of the code that I am using at the moment.
Many thanks!!

Private Function fnValidateEntry() As Boolean
Dim bolPartValidate As Boolean
bolPartValidate = False
fnValidateEntry = False
If IsNull(Me.cboSelectDonor) Then
bolPartValidate = False
If MsgBox("You must select a donor. Click OK to complete the entry.
Click Cancel to continue without saving the record.", vbOKCancel, "Missing
Information") = vbOK Then
Me.cboSelectDonor.SetFocus
Else
If Me.Dirty Then
Me.Undo
End If
End If
Else
bolPartValidate = True
End If
ElseIf IsNull(Me.cboDonorAddress) Then
bolPartValidate = False
If MsgBox("You must select a donor address. Click OK to complete the
entry. Click Cancel to continue without saving the record.", vbOKCancel,
"Missing Information") = vbOK Then
Me.cboDonorAddress.SetFocus
Else
If Me.Dirty Then
Me.Undo
End If
End If
Else
bolPartValidate = True
End If
ElseIf IsNull(Me.cboReceiptTo) Then
bolPartValidate = False
If MsgBox("You must designate a receipt recipient. Click OK to
complete the entry. Click Cancel to continue without saving the record.",
vbOKCancel, "Missing Information") = vbOK Then
Me.cboReceiptTo.SetFocus
Else
If Me.Dirty Then
Me.Undo
End If
End If
Else
bolPartValidate = True
End If
ElseIf IsNull(Me.cboCampaign) Then
bolPartValidate = False
If MsgBox("You must select a campaign. Click OK to complete the
entry. Click Cancel to continue without saving the record.", vbOKCancel,
"Missing Information") = vbOK Then
Me.cboCampaign.SetFocus
Else
If Me.Dirty Then
Me.Undo
End If
End If
Else
bolPartValidate = True
End If
ElseIf IsNull(Me.cboFund) Then
bolPartValidate = False
If MsgBox("You must select a fund. Click OK to complete the entry.
Click Cancel to continue without saving the record.", vbOKCancel, "Missing
Information") = vbOK Then
Me.cboFund.SetFocus
Else
If Me.Dirty Then
Me.Undo
End If
End If
Else
bolPartValidate = True
End If
ElseIf IsNull(Me.txtOrganization) Then
bolPartValidate = False
If MsgBox("You must select either CZCA or ASI. Click OK to complete
the entry. Click Cancel to continue without saving the record.", vbOKCancel,
"Missing Information") = vbOK Then
Me.txtOrganization.SetFocus
Else
If Me.Dirty Then
Me.Undo
End If
End If
Else
bolPartValidate = True
End If
ElseIf IsNull(Me.curDonationAmount) Then
bolPartValidate = False
If MsgBox("You must enter a donation amount. Click OK to complete
the entry. Click Cancel to continue without saving the record.", vbOKCancel,
"Missing Information") = vbOK Then
Me.curDonationAmount.SetFocus
Else
If Me.Dirty Then
Me.Undo
End If
End If
Else
bolPartValidate = True
End If
ElseIf IsNull(Me.dtDonationPaymentDate) Then
bolPartValidate = False
If MsgBox("Did you intend to mark this donation as paid. Click Yes
to return to the record. Click No to leave the donation unpaid.", vbYesNo,
"Payment Information") = vbYes Then
Me.ynDonationPaid.SetFocus
Else
bolPartValidate = True
End If

ElseIf bolPartValidate = True Then
If Me.curDonationAmount >= 1000 Then
If MsgBox("This donation requires follow-up. Does it require any special
action? Click Yes to return to the record and enter the special actions in
the Comment field. Or click No to continue. A letter will be sent by
default.", vbYesNo, "Follow Up Required") = vbYes Then
fnValidateEntry = False
Me.memDonationComment.SetFocus
Else
fnValidateEntry = True
End If
End If
End If
End If
End Function
 
G

gael

Jeanette Cunningham said:
Hi Tal,
Try it like this-->

Private Function fnValidateEntry() As Boolean
Dim bolPartValidate as Boolean
bolPartValidate = False
fnValidateEntry = False
If IsNull(Me.cboSelectDonor) Then
bolPartValidate = False
If MsgBox("You must select a donor. Click OK to complete the entry.
Click Cancel to continue without saving the record.", vbOKCancel, "Missing
Information") = vbOK Then
Me.cboSelectDonor.SetFocus
Else
If Me.Dirty Then
Me.Undo
End If
Else
bolPartValidate = True
End If

ElseIf IsNull(Me.cboDonorAddress) Then
bolPartValidate = False
If MsgBox("You must select a donor address. Click OK to complete the
entry. Click Cancel to continue without saving the record.", vbOKCancel,
"Missing Information") = vbOK Then
Me.cboDonorAddress.SetFocus
Else
If Me.Dirty Then
Me.Undo
End If
Else
bolPartValidate = True
End If

ElseIf IsNull(Me.dtDonationPaymentDate) Then
bolPartValidate = False
If MsgBox("Did you intend to mark this donation as paid. Click Yes to
return to the record. Click No to leave the donation unpaid.", vbYesNo,
"Payment Information") = vbYes Then
Me.ynDonationPaid.SetFocus
Else
End If
Else
bolPartValidate = True
End If

If bolPartValidate = True Then
If Me.curDonationAmount >= 1000 Then
If MsgBox("This donation requires follow-up. Does it require any
special
action? Click Yes to return to the record and enter the special actions in
the Comment field. Or click No to continue. A letter will be sent by
default.", vbYesNo, "Follow Up Required") = vbYes Then
fnValidateEntry = True
Me.memDonationComment.SetFocus
Else
fnValidateEntry = True
End If
End If
End If
End Function



Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia




je pas
je 7ans
 
J

Jeanette Cunningham

Change this line-->

ElseIf bolPartValidate = True Then
If Me.curDonationAmount >= 1000 Then


to-->
If bolPartValidate = True Then
If Me.curDonationAmount >= 1000 Then


In other words, change the ElseIf to a plain If

That is how I originally wrote it.

The code goes through all the controls to see if any are missing a value.
If any of them are missing a value, then bolPartValidate is False.


After the code has checked all the controls and found that they all have a
value, then it sets bolPartValidate to true.

Only it bolPartValidate is true does it do the last bit of code. This last
bit of code is has its own If and End If and is a separate block within the
function.

In other words there are 2 separate blocks of code within that function.

The first block starts with If and ends with End If.

The second block starts with If and ends with End If.



If bolPartValidate = True Then
If Me.curDonationAmount >= 1000 Then
If MsgBox("This donation requires follow-up. Does it require any special
action? Click Yes to return to the record and enter the special actions in
the Comment field. Or click No to continue. A letter will be sent by
default.", vbYesNo, "Follow Up Required") = vbYes Then
fnValidateEntry = True
Me.memDonationComment.SetFocus
Else
fnValidateEntry = True
End If
End If
End If


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
T

Tal

Hi Jeanette and Douglas,

I finally have everything up and working perfectly.
Thanks for all your help.

Cheers,
Tal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top