I am using the following code to validate the user input. It can only be in one of 6 formats as explained in the IF stmt below. If a user enters an incorrect format the Call Msgbox Invalid postcode pops up.
However the second msgbox which is called when the user enters the correct input is not working properly. As you can see there are 6 valid options, only when the user enters the last correct input (i.e. If Not Text1.Text Like "[A-Z][A-Z][0-9][A-Z] [A-Z][A-Z][A-Z]" Then) does the text msg box appear telling you what you have entered.
For the other 5 options it doesn’t do anything?
I would be very grateful if you could have a look and see why this might be.![]()
VB Code:
Private Sub CommandButton1_Click() '6 combinations of valid postcodes AN, AAN, ANN, AANN, ANA, AANA If Not Text1.Text Like "[A-Z][0-9] [A-Z][A-Z][A-Z]" Then If Not Text1.Text Like "[A-Z][A-Z][0-9] [A-Z][A-Z][A-Z]" Then If Not Text1.Text Like "[A-Z][0-9][0-9] [A-Z][A-Z][A-Z]" Then If Not Text1.Text Like "[A-Z][A-Z][0-9][0-9] [A-Z][A-Z][A-Z]" Then If Not Text1.Text Like "[A-Z][0-9][A-Z] [A-Z][A-Z][A-Z]" Then If Not Text1.Text Like "[A-Z][A-Z][0-9][A-Z] [A-Z][A-Z][A-Z]" Then Call MsgBox("Invalid Postcode, please re-enter.", vbExclamation, "Error") Text1.SetFocus Else MsgBox "The Postcode you have entered is """ & Text1.Text & """" Exit Sub End If End If End If End If End If End If End Sub




Reply With Quote