I'm trying to add a validation on a box within a userform that I am working on. I want to make sure that if the user selects the value Direct within a combo box within the userform, they will be unable to leave the TxtAmt box empty. They will have to enter a numeric value within the box if Direct is selected. I thought if I added
If Me.cboDirectIndirect.Value = "Direct" Then
Me.TxtAmt.Text <> ""
End If
Users would no longer be able to leave the amount box blank. Unfortunately, I cannot even get to the testing phase, because I encounter a Compile Error: Expected expression, and the <> operator is highlighted. I also tried to write it using
instead of
But that didn't work either. Can anyone tell me what I am doing wrong? I added the if statement at the end of the sub-query. Here's the entire sub-query:
Private Sub txtAmt_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Me.txtAmt.Value = "" Then
Me.OverShortAmt.Caption = ""
Cancel = True
MsgBox ("Amount Box cannot be empty! Please enter in a dollar amount in Numeric Form.")
Exit Sub
ElseIf Not IsNumeric(Me.txtAmt.Value) And Me.txtAmt.Value <> "" Or Me.txtAmt.Value = " " Then
Cancel = True
MsgBox ("Please enter in a valid numeric amount! NO TEXT OR SPACES!")
Exit Sub
End If
With Me.OverShortAmt
If Me.txtAmt.Value < 0 Then
.BackStyle = fmBackStyleTransparent
.BackColor = rgbAquamarine
.ForeColor = vbRed
.Caption = "Short"
.Font = Bold
Else
.BackStyle = fmBackStyleTransparent
.BackColor = rgbWhite
.ForeColor = vbBlack
.Caption = "Over"
.Font = Bold
End If
End With
If Me.txtAmt.Value = "" Then
Me.OverShortAmt.Caption = ""
End If
If Me.cboDirectIndirect.Value = "Direct" Then
Me.txtAmt.Text <> ""
End If
End Sub
I appreciate any and all help. Thanks!
Bookmarks