Consulting

Results 1 to 5 of 5

Thread: VBA Date Range Argument

  1. #1

    VBA Date Range Argument

    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:

    [VBA]' 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
    [/VBA]
    I hope someone can help me. Thanks!

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    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

  3. #3
    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!

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    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

    Mark

  5. #5
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    I am afraid that I cannot find the additional control "Microsoft Date and Time Picker Control" in 2003.

    Sorry I could not help,

    Mark

Posting Permissions

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