Consulting

Results 1 to 3 of 3

Thread: UF validation based on date

  1. #1

    UF validation based on date

    Good morning,

    I run a small validation check on a userform (XL 2007) when a handler clicks ok.. for example "it textbox1 empty then "msg box".

    How do i run the validation to be

    If this date b is before date A "msg box"

    The complicated thing is that I run the dates input as three boxes.. this is validated onto the spreadsheet as follows:

    .Offset(RowCount, 5).Value = CDate(Me.cboDay1.Value & "/" & Me.cboMonth1.Value & "/" & Me.cboYear1.Value & " " & Me.TextBox1.Value)
        .Offset(RowCount, 6).Value = CDate(Me.cboDay2.Value & "/" & Me.cboMonth2.Value & "/" & Me.cboyear2.Value & " " & Me.TextBox2.Value)
    IS this even possible? as in when I exit the last boxes rather than just on validating on "OK"?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Do you mean something like

    Private Sub cboDay1_AfterUpdate()
        Call CheckDates
    End Sub
    Private Sub cboMonth1_AfterUpdate()
        Call CheckDates
    End Sub
    Private Sub cboYear1_AfterUpdate()
        Call CheckDates
    End Sub
    Private Sub cboDay2_AfterUpdate()
        Call CheckDates
    End Sub
    Private Sub cboMonth2_AfterUpdate()
        Call CheckDates
    End Sub
    Private Sub cboYear2_AfterUpdate()
        Call CheckDates
    End Sub
    
    Private Sub CheckDates()
    Dim dateA As Date
    Dim dateB As Date
    
        With Me
        
            If .cboDay1.ListIndex >= 0 And .cboMonth1.ListIndex >= 0 And .cboYear1.ListIndex >= 0 And _
                .cboDay2.ListIndex >= 0 And .cboMonth2.ListIndex >= 0 And .cboYear2.ListIndex >= 0 Then
                
                dateA = DateSerial(.cboYear1.Value, .cboMonth1.Value, .cboDay1.Value)
                dateB = DateSerial(.cboYear2.Value, cboMonth2.Value, .cboDay2.Value)
                
                If dateA > dateB Then MsgBox "Greater"
            End If
        End With
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    perfect.!!! few little tweaks to check other bits but thats perfect.

    cheers

Posting Permissions

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