PDA

View Full Version : [SOLVED] Format in TextBox



oleneazer
09-09-2004, 01:55 PM
Hello

The goal is: In a userform, a textbox to fill only with dates

I find to do the following stuff:


Sub UserForm1_Initialize()
TextBox1.Value=Format("the date","dd/mm/yyyy")
End Sub

The result must be that when UserForm1.SHow
the texbox looks like ../../....
and that you will only fill the textbox with date
I try with :


If IsNot Texbox1.Value=Format("...","dd/mm/yyyy" ) Then
MsgBox "Saisie invalide", vbCritical, "Attention"

or


UserForm1.Hide

In what direction I must search the solution?

I hope that what i have wrote is "limpide"

Zack Barresse
09-09-2004, 01:58 PM
Hi,

If you're looking to check the date for a valid date, check out the IsDate method. Maybe something like this ..


If IsDate(Texbox1.Value) = False Then
MsgBox "Saisie invalide", vbOkOnly + vbCritical, "Attention"
End If

oleneazer
09-10-2004, 08:14 AM
Hi,

If you're looking to check the date for a valid date, check out the IsDate method. Maybe something like this ..


If IsDate(Texbox1.Value) = False Then
MsgBox "Saisie invalide", vbOkOnly + vbCritical, "Attention"
End If
The goal I want to reach is that the two / / appear
in the textbox when UserForm1.Show, to avoid to write them in the textbox
The user can only write :
two numbers for the day then the cursor goes behind the first /
then two numbers for the month (the cursor goes behind the 2nd /)
and finally four numbers for the year.
Until the user has not write a valid date, he can't close the UserForm.

Zack Barresse
09-10-2004, 09:11 AM
I don't know how to do that. If that's the case, I'd just suggest to you make 3 text box's, or 3 combobox's. I've attached an example just to show you. The combobox's have values input in them upon initialization of the userform. Just a couple of idea's.

oleneazer
09-11-2004, 01:38 PM
I don't know how to do that. If that's the case, I'd just suggest to you make 3 text box's, or 3 combobox's. I've attached an example just to show you. The combobox's have values input in them upon initialization of the userform. Just a couple of idea's.Thanks for your answer and for your file Firefytr
It had help to better understand yuse use of For .. To ..

By my side, after a long time of thinking and with help find on the internet
Here it is the code that I use at this moment.


Private Sub CommandButton1_Click()
With Sheets(1).[A1]
.Value = TextBox1.Value
.NumberFormat = "mm/dd/yy"
End With
End Sub

Private Sub CommandButton2_Click()
Me.Hide
End Sub
Private Sub TextBox1_Change()
Select Case Len(TextBox1)
Case 2, 5: TextBox1 = TextBox1 & "/"
End Select
End Sub

Private Sub UserForm_Initialize()
TextBox1.Value = ""
End Sub