Multiple Ifs and Elses - how do you bracket them....

G

Guest

I have a order form with a tick box which when clicked on runs a series of
checks to check certain options against the order.

The system should work as follows..

When Order_Entry_Complete is clicked,
check to see if the order is on a proforma basis
if it is then do nothing and accept the order..

If the order is not proforma then check to see that the order total is not
greater than the customer's credit limit. If it is, display a msg box warning
them of this but allow them to click ok anyway or cancel.

If it iisn't, display a msgbox informing that user that when they click ok
the order will be accepted and they won't be able to make any changes.

I've got 99% of the code for this, but I can't seem to work out where and
how to end my if and if statements and it's annoying me as it's relatively
simple but just doesn't quite work.

Private Sub Order_Entry_Complete_Click()
If Terms = "Proforma" Then
Me.Requery
Exit Sub
Else


If Me.OrderTotal > Me.CreditLimit Then
RetValue2 = MsgBox("This order is for a higher value than this customer's
credit limit! Check with Robin and Karen before proceeding! If you click OK,
this order will be accepted, click cancel if you need to consult
management.", vbOKCancel)
End If

If RetValue2 = vbOK Then
Me.Requery
Else
Exit Sub
End If

Else

RetValue3 = MsgBox("By clicking OK you confirm that you have finished
entering all the details for this order. If you have not finished, then click
cancel.", vbOKCancel)
If RetValue3 = vbOK Then
Me.Requery
Else
Order_Entry_Complete = False
End If

End Sub
 
G

Guest

Private Sub Order_Entry_Complete_Click()
If Terms = "Proforma" Then
Me.Requery
Exit Sub
End If 'No need for an Else after this, you are out of the sub

If Me.OrderTotal > Me.CreditLimit Then
RetValue2 = MsgBox("This order is for a higher value than this customer's
credit limit! Check with Robin and Karen before proceeding! If you
click OK,
this order will be accepted, click cancel if you need to consult
management.", vbOKCancel)
End If

If RetValue2 = vbOK Then
Me.Requery ' This will not update your data, where do you do that.
Exit Sub
Else
RetValue3 = MsgBox("By clicking OK you confirm that you have finished
entering all the details for this order. If you have not finished,
then click
cancel.", vbOKCancel)
If RetValue3 = vbOK Then
Me.Requery
Exit Sub
Else
Order_Entry_Complete = False
End If
End If

End Sub
Hint: It make your code easier to read if you use good indenting:

If Condition Then
Do Something
If Condition Then
Do Something
Else
Do Something Else
Endif
Else
Do Until Done
Do Repetative Stuff
End Do
End If

Is much easier to read than

If Condition Then
Do Something
If Condition Then
Do Something
Else
Do Something Else
Endif
Else
Do Until Done
Do Repetative Stuff
End Do
End If
 

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