PDA

View Full Version : [SOLVED] UF validation based on date



CuriousGeorg
02-03-2014, 01:34 AM
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"?

Bob Phillips
02-03-2014, 02:00 AM
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

CuriousGeorg
02-03-2014, 02:34 AM
perfect.!!! few little tweaks to check other bits but thats perfect.

cheers