• control date entry

    Author
    Topic
    #463505

    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
    ù

    Viewing 0 reply threads
    Author
    Replies
    • #1183446

      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
      • #1183448

        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

        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)

        • #1183449

          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
          • #1183451

            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

            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.?

            • #1183453

              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”?

            • #1183454

              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”?

              correct date based the current year…

            • #1183458
              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
            • #1183461
              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

              🙂

    Viewing 0 reply threads
    Reply To: control date entry

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: