Hi,
I have two text boxes for which I am trying have show and error message when the proper data is not entered. One text box is for PLANID and the other is for Date. I would like the PLANID to be checked 1st. The PLANID needs to be either 7 digits or 10. If it is not, the message would be "Please enter a valid PLANID". If it is 7 or 10 digits, then it should check the Date text box. If it is blank, the message would be "Please enter a valid Date". If they are both blank, the PLANID message should appear 1st. Below is what I have written. The problem that I am having is that when the PLANID is 10 digits and the date is blank, the "Please enter a valid PLANID" message is showing rather than the "Please enter a valid Date" message.
Can someone please let me know what I am doing wrong? Thanks.
Private Sub Btn_Refresh_Data_for_One_Plan_Click()
Me.txtboxPLANID.Value = UCase(Me.txtboxPLANID.Value)
If ((Len(Me.txtboxPLANID.Value) = 7 And Len(Me.txtboxPLANID.Value) = 10) And (Not IsNull(Me.txtboxPLANID.Value)) And (Not IsNull(Me.TxtboxDate.Value))) Then
Dim stDocName As String
stDocName = "Mcr_RUN_MATCH_DIFFERENCES"
DoCmd.RunMacro stDocName
Else
If ((Len((Me.txtboxPLANID.Value) < 7) And Len((Me.txtboxPLANID.Value) > 10)) Or IsNull(Me.txtboxPLANID.Value)) Then
InvalidPlanIdMsg
Else
If ((Len((Me.txtboxPLANID.Value) = 7) Or Len((Me.txtboxPLANID.Value) = 10)) And IsNull(Me.TxtboxDate.Value)) Then
InvalidDateMsg
End If
End If
End If
End Sub
Private Sub InvalidDateMsg()
MsgBox ("Please enter a valid Date!")
Me.TxtboxDate.SetFocus
End Sub
Private Sub InvalidPlanIdMsg()
MsgBox ("Please enter a valid Planid!")
Me.txtboxPLANID.SetFocus
End Sub