|
-
Dec 3rd, 2005, 06:21 AM
#1
Thread Starter
Junior Member
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.
-
Dec 3rd, 2005, 06:29 AM
#2
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:
If txtArrival.Text = "" Then 'no date for arrival chosen
txtArrival.Text = calender1.Value
Else
txtdeparture.Text = calender1.Value
End If
-
Dec 3rd, 2005, 06:35 AM
#3
Thread Starter
Junior Member
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?
-
Dec 3rd, 2005, 06:42 AM
#4
Re: Quick problem!!!
VB Code:
DateDiff("d", DTPicker1.Value, DTPicker2.Value)
or
VB Code:
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.
-
Dec 3rd, 2005, 06:49 AM
#5
Thread Starter
Junior Member
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?
-
Dec 3rd, 2005, 06:57 AM
#6
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:
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
-
Dec 3rd, 2005, 06:59 AM
#7
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
-
Dec 3rd, 2005, 07:09 AM
#8
Thread Starter
Junior Member
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)
-
Dec 3rd, 2005, 07:16 AM
#9
Thread Starter
Junior Member
Re: Quick problem!!!
Dont answer that,!
im a spa
it should have been lblDisplayDuration
as you can see im a beginner
-
Dec 3rd, 2005, 07:18 AM
#10
Re: Quick problem!!!
Oops, I realise the error i made now. Try
VB Code:
If Len(txtarrival) > 0 And Len(txtdeparture) > 0 Then
Label.captin = DateDiff("d", txtarrival.Text, txtdeparture.Text)
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.
-
Dec 3rd, 2005, 07:29 AM
#11
Thread Starter
Junior Member
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?
-
Dec 3rd, 2005, 07:32 AM
#12
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.
-
Dec 3rd, 2005, 07:43 AM
#13
Re: Quick problem!!!
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
-
Dec 3rd, 2005, 07:45 AM
#14
Thread Starter
Junior Member
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.
-
Dec 3rd, 2005, 08:02 AM
#15
-
Dec 3rd, 2005, 08:06 AM
#16
Thread Starter
Junior Member
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
-
Dec 3rd, 2005, 08:10 AM
#17
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 ....
-
Dec 3rd, 2005, 08:17 AM
#18
Thread Starter
Junior Member
Re: Quick problem!!!
no dice
it also happens when i press the clear button
-
Dec 3rd, 2005, 12:29 PM
#19
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:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|