Text box on VBA form to only accept dd/mm/yyyy. Msg if not.

MAButler

New Member
Joined
Mar 30, 2011
Messages
35
I have a form created in VBA, In the form is a number of textboxes..... What i need is if i dont put a date in txtDate a message tells me to insert correct date (dd/mm/yyyy).

Every time i use codes i have found on this forum it goes into a loop and i have to ctrl/alt/delete to get out of it....

<!-- BEGIN TEMPLATE: bbcode_code -->

[Code:]
Private Sub cmdCancel_Click()
ModAdvFilter.CancelProcess = True
Me.Hide
Unload Me
End Sub

Private Sub cmdOK_Click()
ModAdvFilter.CancelProcess = False
ModAdvFilter.RegInfo = Me.txtReg.Text
ModAdvFilter.SerialNum = Me.txtSN.Text
ModAdvFilter.TheDate = Me.txtDate.Text
Me.Hide
Unload Me
End Sub


Private Sub txtDate_Change()
Me.cmdOK.Enabled = HasCriteria

End Sub

Private Sub txtReg_Change()
Me.cmdOK.Enabled = HasCriteria
End Sub

Private Sub txtSN_Change()
Me.cmdOK.Enabled = HasCriteria
End Sub

Private Sub UserForm_Initialize()
ModAdvFilter.CancelProcess = True
Me.cmdOK.Enabled = HasCriteria
txtDate.Text = Format(Date, "dd/mm/yyyy")
End Sub

Private Function HasCriteria() As Boolean
If Len(Trim(Me.txtDate)) > 0 Or Len(Trim(Me.txtReg)) > 0 Or Len(Trim(Me.txtSN)) > 0 Then
HasCriteria = True
Else
HasCriteria = False
End If
End Function
[/code]
Please help it is driving me mad........
<!-- / message --><!-- BEGIN TEMPLATE: ad_showthread_firstpost_sig --><!-- END TEMPLATE: ad_showthread_firstpost_sig -->
<!-- controls -->http://www.excelforum.com/excel-programming/772499-text-box-only-accept-dd-mm-yyyy-msg-if-not.html
progress.gif

<STYLE>.alt2 font {font: 11px monospace !important;color: #333 !important;}</STYLE>
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
In cmdOK_Click, in place of:-
Code:
Me.Hide
Unload Me
try:-
Code:
if isdate(txtdate) then 
  Me.Hide
  Unload Me
else
  msgbox "Argh - duff date!"
endif

(If I've understood you correctly.)
 
Upvote 0
Ha Ha so easy........ been on that for nights.....

On one of my forms they dont have to fill all the textboxes, ie if the dont know the date but they know the name they search with the txtDate box empty.

Is there something to add to your code to let example search
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,234
Members
452,898
Latest member
Capolavoro009

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top