Results 1 to 2 of 2

Thread: Calender Date help plz!!!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Posts
    21

    Arrow Calender Date help plz!!!

    Hey guys,

    I am currently working on a database with the ability to input dates with clicks on the built in calender.

    There are rules which the program must abide by for this program when the user clicks on a date.

    1. - an input date must be 7 days in advance
    2 - an input date must also be within 2 months.

    Here's my code for this feature:

    VB Code:
    1. Private Sub Calendar1_Click()
    2. datetxt.Text = Calendar1.Value
    3. date1 = datetxt.Text
    4. If date1 < (date + 7) Then
    5.     MsgBox "Please book at least 7 days in advance"
    6. If date1 > (date + 60) Then
    7.     MsgBox "You cannot book more than 2 months in advance"
    8. End If
    9. End If

    However, the above code does not work!
    NO matter where i click on the calender, the msgboxes never come up!!

    Thanks for any help!!!

  2. #2
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Calender Date help plz!!!

    Try This:

    VB Code:
    1. Private Sub Calendar1_Click()
    2. On Error GoTo Calendar1_Click_Error
    3. Dim dtValue As Date
    4.  
    5. DateTxt.Text = Calendar1.Value
    6. dtValue = DateTxt.Text
    7.  
    8. If IsDate(dtValue) Then
    9.     If dtValue > DateAdd("d", 7, Date) And dtValue < DateAdd("m", 2, Date) Then
    10.         MsgBox "This is a valid date because it is more than 7 days and less than two Months", vbInformation, "Valid Date"
    11.     ElseIf dtValue <= DateAdd("d", 7, Date) Then
    12.         MsgBox "Please book at least 7 days in advance", vbCritical, "Valid Date"
    13.     ElseIf dtValue >= DateAdd("m", 2, Date) Then
    14.         MsgBox "You cannot book more than 2 months in advance", vbCritical, "Valid Date"
    15.     End If
    16. Else
    17.     MsgBox "This is an invalid Date Value"
    18. End If
    19.  
    20.  
    21. On Error GoTo 0
    22. Exit Sub
    23.  
    24. Calendar1_Click_Error:
    25.  
    26. If Err.Number = 13 Then
    27.     MsgBox "Please enter a valid date value.", vbCritical, "Invalid Date"
    28. Else
    29.     MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Calendar1_Click of Form Form1"
    30. End If
    31. End Sub
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


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