CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 1999
    Location
    Israel
    Posts
    140

    Checking Date range

    I want to make a small dialog box which contains
    "From Date" and "To Date" input user fields .
    I need to validate that the dates inserted by the user are correct.
    Is there any code around that do somthing similar?


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: Checking Date range

    try the IsDate function. It returns False for invalid dates.


  3. #3
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Re: Checking Date range

    I would do it with two date picker controls:


    private Sub Form_Initialize()
    'initialize controls
    DTPicker1.Value = Now
    DTPicker2.Value = Now
    DTPicker1.MaxDate = Now
    DTPicker2.MaxDate = Now
    DTPicker2.MinDate = Now
    End Sub

    private Sub DTPicker1_Validate(Cancel as Boolean)
    'set the earliest date for dtpicker2 equal to the selected date from dtpicker1
    DTPicker2.MinDate = DTPicker1.Value
    End Sub



    You can retrieve the values entered with the value property of each dtpicker control. For any further questions, post them here! ;-)

    Michael Vlastos
    Automation Engineer
    Company SouthGate Hellas SA
    Development Department
    Athens, Greece

  4. #4
    Join Date
    Nov 1999
    Location
    US NJ
    Posts
    113

    Re: Checking Date range

    Try this

    Private Sub Command1_Click()
    Dim Date1 As Date
    Dim Date2 As Date
    Date1 = Format(Text1, "dd/mm/yyyy")
    Date2 = Format(Text2, "dd/mm/yyyy")
    If Date1 - Date2 >= 0 Then
    MsgBox "Please enter the correct dates"
    End If
    End Sub

    It works for me.

    Good luck.
    Leo


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured