Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EXCEL 2003 VBA FIELD VALIDATION HELP 2

Status
Not open for further replies.

Evil8

MIS
Mar 3, 2006
313
US
I managed to create a UserForm in VBA for an Excel 2003 for inputing variable strings and one date. Now I would like to add validation to some of the fields so that it won't run if the fields are blank & if the date field is not in dd/mm/yyyy format.

I tried both Private Sub txt_cName_Change() and
Private Sub txt_cName_AfterUpdate()

Neither of these did anyting if the user skips the Company Name field.

Private Sub txt_cName_AfterUpdate()
If Me.txt_cName.Value = "" Then
MsgBox "You must type in a Company Name for this report", vbExclamation, "Company Name"
Me.txt_cName.SetFocus
End If
End Sub

Thank You for all your help.
 
How is the data on the form processed? That is, is there a button that is pressed to indicate that the data should be taken in? If so, that's where your validation should be performed.

Think of it this way: if the user skips a field, there's no update to be after.

_________________
Bob Rashkin
 
You can:
Code:
Private Sub txt_cName_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Me.txt_cName.Value = "" Then
    MsgBox "You must type in a Company Name for this report", vbExclamation, "Company Name"
    Cancel = True
End If
End Sub

combo
 
That makes sense now! Add the validation to the OK button with all the other commands. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top