PDA

View Full Version : VBA Date Range Argument



aplfalcon
04-12-2010, 12:21 PM
Hi,

I have two DTPickers in my userform. They will be used to select a date range. I want to write code that will pop-up a message box and prevent the user from continuing if the user selects an end date which is before the start date. For example, if the start date is 4/12/2010, the user cannot select an end date that is 4/11/2010 or earlier.

This is probably horribly wrong (I'm a novice), but here's what I've tried:

' The DTPicker code:
Private Sub EndDatePicker_CallbackKeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer, ByVal CallbackField As String, CallbackDate As Date)
' My Code:
IF EndDatePicker.DateValue("<"&StartDatePicker.Value) THEN
MsgBox "You cannot enter an end date which occurs before the start date."
EndDatePicker.SetFocus
Exit Sub
End If
End Sub

I hope someone can help me. Thanks!

GTO
04-12-2010, 12:27 PM
Greetings aplfalcon,

Welcome to vbaexpress :-)

Say, for the thicker-headed fellas amongst us (namely me), could you attach an example workbook with the userform and enough of the code so that we can see what needs done?

Mark

aplfalcon
04-12-2010, 12:33 PM
Hi GTO,

Thanks :)
I'm sure I'll be on here regularly as I learn the ropes.

Attached is my workbook. I'm embarrassed to say there's not much going on yet.

Open the VBE and then click on "AEDA." That's where the userform is located. I don't have real data to work with yet so I have dummy data from another project in the data worksheet of the workbook.

Thanks!

GTO
04-12-2010, 01:11 PM
:oops: My bad. At home, so am dependant upon my poor ol' xl2000 and no room to install the patch. I'm currently working a late schedule, so off to bed in a bit, but may be able to check from work later.

As a general suggestion, I would save example wb's in .xls format, as there's plenty of folks here who can be of great help, but have older versions.

Sorry I did not previously mention:doh:

Mark

GTO
04-13-2010, 06:13 AM
I am afraid that I cannot find the additional control "Microsoft Date and Time Picker Control" in 2003.

Sorry I could not help,

Mark