![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Mar 2002
Posts: 88
|
I need some code to check that a field is filled out before allowing the user to submit on a custom userform. Basically I have a date field in the custom form and I need to make SURE the user fills in that field but proceeding. So I need code to check the date field for a valid value when they click "ok". If there is not a value I need it to pop up the user an error saying something like "Date Field must be completed" Please Help, Thanks...
|
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
|
Keith,
This code assumes that your textbox is called txtDate and your OK button is called cmdOK. Hope it helps, D Code:
Private Sub cmdOK_Click()
If Not IsDate(txtDate.Text) Then
MsgBox "Date field is not a valid date.", vbExclamation, "Error"
Me.txtDate.Text = ""
Me.txtDate.SetFocus
Exit Sub
ElseIf txtDate.Text = "" Then
MsgBox "Date field must be completed.", vbExclamation, "Error"
Me.txtDate.Text = ""
Me.txtDate.SetFocus
Exit Sub
End If
'Rest of your code
MsgBox "Congratulations! You entered a valid date"
End Sub
|
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Mar 2002
Posts: 88
|
Works like a charm! Thanks tremendously..
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|