Results 1 to 19 of 19

Thread: Quick problem!!!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    23

    Quick problem!!!

    How do i get a calendar function to display both arrival and depature dates in seperate text boxes?
    Last edited by MickyMc; Dec 3rd, 2005 at 07:06 AM.

  2. #2
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Quick problem!!!

    You can always use "Microsoft Common Windows controls 2 6.0" as it has a date picker dropdown. So all you need is two, one for arrival and the other for departure. Using this you can also set the min date etc. But if you really just want to use the calender
    VB Code:
    1. If txtArrival.Text = "" Then    'no date for arrival chosen
    2.     txtArrival.Text = calender1.Value
    3. Else
    4.     txtdeparture.Text = calender1.Value
    5. End If

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    23

    Re: Quick problem!!!

    Thanks that code worked For me

    1 more question

    i have a label under the text boxes that i want to display how many nights the person is staying when they click on the arrival and departure dates.

    i have tried this code but it does not appear

    lblDisplayDuration.Caption = DateDiff("d", Date1, Date2) & "Nights"


    Any ideas?

  4. #4
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Quick problem!!!

    VB Code:
    1. DateDiff("d", DTPicker1.Value, DTPicker2.Value)
    or
    VB Code:
    1. DateDiff("d", txtarrival.text, txtdeparture.text)
    Oh and you don't need to change the first post, as future people may have a similar question and hence when they search, they won't get this post.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    23

    Re: Quick problem!!!

    Again that works!
    But it only appears if you click on the label, which is practically invisible.

    Any way of getting the words to automatically appear when the 2 text boxes are full?

  6. #6
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Quick problem!!!

    put this under both the txtarrival_change and txtdeparture_change subs so that it runs when the text box has been changed.

    VB Code:
    1. If Len(txtarrival) > 0 And Len(txtdeparture) > 0 Then
    2.     Label.captin = DateDiff("d", txtarrival.Text, txtdeparture.Text)
    3. Else
    4.     MsgBox "Please enter both an arrival date and departure date"
    5. End If

  7. #7
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Quick problem!!!

    Could you please, edit your first post and rewrite your original question?
    Many people search the forums for help, it would be nice having that first question in the first post

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    23

    Re: Quick problem!!!

    thanks andrew but i am having problems with that code.

    when i click on the first date a message box appears telling me to enter 2 dates.
    then when i click on the second date there is an error .

    the problem line is

    LabelDisplayDuration.Caption = DateDiff("d", txtArrival.Text, txtDeparture.Text)

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    23

    Re: Quick problem!!!

    Dont answer that,!
    im a spa
    it should have been lblDisplayDuration

    as you can see im a beginner

  10. #10
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Quick problem!!!

    Oops, I realise the error i made now. Try
    VB Code:
    1. If Len(txtarrival) > 0 And Len(txtdeparture) > 0 Then
    2.     Label.captin = DateDiff("d", txtarrival.Text, txtdeparture.Text)
    3. End If
    That way you don't get an msgbox.

    One quick question, what format is the date in the two boxes, since this could be creating the problem.

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    23

    Re: Quick problem!!!

    ##/##/####

    Its workin lovely now!

    One last thing!
    How do i make the calendar work from today onwards so that a customer cannot enter in yesterdays date?

  12. #12
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Quick problem!!!

    do another datediff (using today's date and txtarrival) when the user enters data into the txtarrival box and then check if its a negative number, if it is the you can send them a message.

  13. #13
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Quick problem!!!

    VB Code:
    1. Private Sub txtarrival_LostFocus()
    2. If DateDiff("d", Date, txtarrival) < 0 Then
    3.     MsgBox "Please enter a date after today"
    4.     txtarrival = Date
    5. End If
    6. End Sub
    7.  
    8. Private Sub txtdeparture_LostFocus()
    9. If DateDiff("d", txtarrival, txtdeparture) < 0 Then
    10.     MsgBox "Please enter a date after Arrival"
    11.     txtdeparture = DateAdd("d", 1, txtarrival)
    12. End If
    13. End Sub

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    23

    Re: Quick problem!!!

    whats the code for todays date?

    as in if this app was used in 2 weeks time the date would automatically change.

  15. #15
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Quick problem!!!

    Date

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    23

    Re: Quick problem!!!

    thanks for the code

    It works but doesnt!
    if i click on yesterdays date the message box pops up
    when i click ok an error 13 appears - 'Type mismatch"

    problem code is
    If DateDiff("d", Date, txtArrival) < 0 Then

  17. #17
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Quick problem!!!

    I think this is becuase one of the dates is not a date. Try putting a > on error resume next at the begining under Private sub ....

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    23

    Re: Quick problem!!!

    no dice

    it also happens when i press the clear button

  19. #19
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Quick problem!!!

    As Andrew G said the error is because one of the dates isn't a date. You need to convert the value of txtArrival.Text into a date, like this:
    VB Code:
    1. If DateDiff("d", Date, CDate(txtArrival.Text)) < 0 Then
    (and the same changes whereever you need to use the textbox values as dates)

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