Consulting

Results 1 to 5 of 5

Thread: Format in TextBox

  1. #1

    Format in TextBox

    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"

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    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

  3. #3
    Quote Originally Posted by firefytr
    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.

  4. #4
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    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.

  5. #5

    The solution is comming soon

    Quote Originally Posted by firefytr
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •