How do i get a calendar function to display both arrival and depature dates in seperate text boxes?
Printable View
How do i get a calendar function to display both arrival and depature dates in seperate text boxes?
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:
If txtArrival.Text = "" Then 'no date for arrival chosen txtArrival.Text = calender1.Value Else txtdeparture.Text = calender1.Value End If
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?
orVB Code:
DateDiff("d", DTPicker1.Value, DTPicker2.Value)
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.VB Code:
DateDiff("d", txtarrival.text, txtdeparture.text)
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?
put this under both the txtarrival_change and txtdeparture_change subs so that it runs when the text box has been changed.
VB Code:
If Len(txtarrival) > 0 And Len(txtdeparture) > 0 Then Label.captin = DateDiff("d", txtarrival.Text, txtdeparture.Text) Else MsgBox "Please enter both an arrival date and departure date" End If
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 ;)
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)
Dont answer that,!
im a spa
it should have been lblDisplayDuration
as you can see im a beginner
Oops, I realise the error i made now. Try
That way you don't get an msgbox.VB Code:
If Len(txtarrival) > 0 And Len(txtdeparture) > 0 Then Label.captin = DateDiff("d", txtarrival.Text, txtdeparture.Text) End If
One quick question, what format is the date in the two boxes, since this could be creating the 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?
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.
VB Code:
Private Sub txtarrival_LostFocus() If DateDiff("d", Date, txtarrival) < 0 Then MsgBox "Please enter a date after today" txtarrival = Date End If End Sub Private Sub txtdeparture_LostFocus() If DateDiff("d", txtarrival, txtdeparture) < 0 Then MsgBox "Please enter a date after Arrival" txtdeparture = DateAdd("d", 1, txtarrival) End If End Sub
whats the code for todays date?
as in if this app was used in 2 weeks time the date would automatically change.
Date
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
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 ....
no dice
it also happens when i press the clear button
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:
(and the same changes whereever you need to use the textbox values as dates)VB Code:
If DateDiff("d", Date, CDate(txtArrival.Text)) < 0 Then