Results 1 to 9 of 9
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I use this code to check a date entry but duibt it work correct....

    Private Sub CommandButton1_Click()

    If Me.TextBox1.Text > "" Then

    If Not IsDate(Format(Me.TextBox1.Text, "DD/MM/YYYY")) Then
    Me.TextBox1.Text = ""
    MsgBox ("DATA ERRATA! INSERIRE NEL FORMATO GG/MM/AAAA"), vbCritical, "MONITORAGGIO"
    Exit Sub
    End If
    Else
    MsgBox ("INSERIRE UNA DATA VALIDA! NEL FORMATO GG/MM/AAAA"), vbCritical, "MONITORAGGIO"
    End If

    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    I'd use

    Code:
    Private Sub CommandButton1_Click()
      If Me.TextBox1.Text = "" Then
    	MsgBox "INSERIRE UNA DATA VALIDA! NEL FORMATO GG/MM/AAAA", vbCritical, "MONITORAGGIO"
      ElseIf Not IsDate(Me.TextBox1.Text) Then
    	Me.TextBox1.Text = ""
    	MsgBox "DATA ERRATA! INSERIRE NEL FORMATO GG/MM/AAAA", vbCritical, "MONITORAGGIO"
      End If
    End Sub

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='800323' date='28-Oct-2009 16:52']I'd use

    Code:
    Private Sub CommandButton1_Click()
      If Me.TextBox1.Text = "" Then
    	MsgBox "INSERIRE UNA DATA VALIDA! NEL FORMATO GG/MM/AAAA", vbCritical, "MONITORAGGIO"
      ElseIf Not IsDate(Me.TextBox1.Text) Then
    	Me.TextBox1.Text = ""
    	MsgBox "DATA ERRATA! INSERIRE NEL FORMATO GG/MM/AAAA", vbCritical, "MONITORAGGIO"
      End If
    End Sub
    [/quote]


    i lov....:-)

    in the userform have a leabel1 is possible, if the date is correct, to insert in this label the day in format dddd (in this case Domenica)

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Perhaps like this:

    Code:
    Private Sub CommandButton1_Click()
      If Me.TextBox1.Text = "" Then
    	MsgBox "INSERIRE UNA DATA VALIDA! NEL FORMATO GG/MM/AAAA", vbCritical, "MONITORAGGIO"
      ElseIf Not IsDate(Me.TextBox1.Text) Then
    	Me.TextBox1.Text = ""
    	MsgBox "DATA ERRATA! INSERIRE NEL FORMATO GG/MM/AAAA", vbCritical, "MONITORAGGIO"
      Else
    	Me.Label1.Caption = Format(Me.TextBox1.Text, "dddd")
      End If
    End Sub

  5. #5
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='800327' date='28-Oct-2009 17:04']Perhaps like this:

    Code:
    Private Sub CommandButton1_Click()
      If Me.TextBox1.Text = "" Then
    	MsgBox "INSERIRE UNA DATA VALIDA! NEL FORMATO GG/MM/AAAA", vbCritical, "MONITORAGGIO"
      ElseIf Not IsDate(Me.TextBox1.Text) Then
    	Me.TextBox1.Text = ""
    	MsgBox "DATA ERRATA! INSERIRE NEL FORMATO GG/MM/AAAA", vbCritical, "MONITORAGGIO"
      Else
    	Me.Label1.Caption = Format(Me.TextBox1.Text, "dddd")
      End If
    End Sub
    [/quote]

    HUMMMMMM...
    but if i insert 25/10/209 the code consider a correct date (year 209) and return mercoledi ..
    i want to controll also the format of date...possible.?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    25 October 209 is a valid date, isn't it?
    If you only want dates in this year, or in this century, you have to test for that.
    And what exactly do you mean by "i want to controll also the format of date"?

  7. #7
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='800331' date='28-Oct-2009 17:17']25 October 209 is a valid date, isn't it?
    If you only want dates in this year, or in this century, you have to test for that.
    And what exactly do you mean by "i want to controll also the format of date"?[/quote]

    correct date based the current year...

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Code:
    Private Sub CommandButton1_Click()
      If Me.TextBox1.Text = "" Then
    	MsgBox "INSERIRE UNA DATA VALIDA! NEL FORMATO GG/MM/AAAA", vbCritical, "MONITORAGGIO"
      ElseIf Not IsDate(Me.TextBox1.Text) Then
    	Me.TextBox1.Text = ""
    	MsgBox "DATA ERRATA! INSERIRE NEL FORMATO GG/MM/AAAA", vbCritical, "MONITORAGGIO"
      ElseIf Not Year(Me.TextBox1.Text) = Year(Date) Then
    	MsgBox "INSERIRE UNA DATA PER L'ANNO IN CORSO, PER FAVORE!", vbCritical, "MONITORAGGIO"
      Else
    	Me.Label1.Caption = Format(Me.TextBox1.Text, "dddd")
      End If
    End Sub

  9. #9
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='800336' date='28-Oct-2009 17:31']
    Code:
    Private Sub CommandButton1_Click()
      If Me.TextBox1.Text = "" Then
    	MsgBox "INSERIRE UNA DATA VALIDA! NEL FORMATO GG/MM/AAAA", vbCritical, "MONITORAGGIO"
      ElseIf Not IsDate(Me.TextBox1.Text) Then
    	Me.TextBox1.Text = ""
    	MsgBox "DATA ERRATA! INSERIRE NEL FORMATO GG/MM/AAAA", vbCritical, "MONITORAGGIO"
      ElseIf Not Year(Me.TextBox1.Text) = Year(Date) Then
    	MsgBox "INSERIRE UNA DATA PER L'ANNO IN CORSO, PER FAVORE!", vbCritical, "MONITORAGGIO"
      Else
    	Me.Label1.Caption = Format(Me.TextBox1.Text, "dddd")
      End If
    End Sub
    [/quote]
    :-)

Posting Permissions

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