Restricted Entry in Userform Text Box

lisauk5583

Board Regular
Joined
Dec 1, 2004
Messages
56
Hi,

I have a text box within a userform that i wish to populate with a date. However, if anything other than a date in format (dd/mm/yy) is entered I want a message box to appear informing user that they must enter a date.

Any ideas would be gratefully received.

Thanks

Lisa
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi lisauk5583
I dont know if this will help but when I needed to delete a particular name from a sheet I used a user form with a combo box
my code was you should be able to adjust it to your situation


Private Sub cmdOK_Click()
Dim Name As String, Rng As Range
If cboName.Text <> Empty Then 'A name was chosen
MsgBox ("You are about to REMOVE a Student!")
'Store name for Deletion
Name = cboName.Text
Else
'No name was chosen
Exit Sub
End If
Me.Hide
Sheets("Student Details").Select
On Error Resume Next
Set Rng = Range("Name").EntireColumn.Find(What:=Name)
If Not Rng Is Nothing Then
Rng.EntireRow.Delete
End If
End Sub
 
Upvote 0
something like this might help/ Or alt. use a datepicker control


Code:
Private Sub CommandButton1_Click()
If Not IsDate(TextBox1.Text) Then
MsgBox ("Date please")
TextBox1.SetFocus
Exit Sub
End If

End Sub
 
Upvote 0
Thanks pcc - that only accepts dates and works fine. However if I enter a date, for example 37/05/92 it doesnt classify this as an error. This is the code I have on the text box.

Code:
On Error Resume Next
    tbReceived.Text = Format(tbReceived.Value, dd / mm / yy)
    If Not IsDate(tbReceived.Text) Then
    MsgBox ("Please enter a valid date")
    tbReceived.SetFocus
    Exit Sub
    End If
End Sub

Any Ideas?

Thanks

Lisa
 
Upvote 0
not sure but could try this. no time right now

Code:
Private Sub CommandButton1_Click()
On Error Resume Next
    TextBox1.Text = Format(TextBox1.Value, "dd/mm/yy")
    
    If Not IsDate(TextBox1.Text) Then
    MsgBox ("Please enter a valid date")
    TextBox1.SetFocus
    Exit Sub
    End If
End Sub
 
Upvote 0
Thanks, that seems to work better. If you input a date that appears wrong it will reset the format to the mosot suitable so for 37/11/05 would become 05/11/37. Thanks for your help.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

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