Making a month picker

Chrism2

Registered User.
Local time
Today, 14:26
Joined
Jun 2, 2006
Messages
161
I'm not sure if I am doing this the right way, but I need some help:

I have two text boxes, txtStartDate and txtEndDate, they have calendar controls which work fine.

I also have a box on the form which has the current year: txtYear

I have created a combo box for the user to quickly pick an entire month range: cboMonth. Naturally, it lists Jan thru Dec.

In it's OnClick properties, I'm trying to get it so that it does something like:
Code:
Dim strYear as String

strYear = me.txtYear.value

If Me.cboPickMonth.Value = "Jan" Then

Me.txtStartDate.Value = "01/01/" & strYear
Me.txtEndDate.Value =  "31/01/" & strYear

End if

'etc for each month


This enters the date - but something about it ain't right because when you then click on the calendar control, I get a type mismatch.


Any clues or suggestions folks?

Thanks
 
Look into the DateSerial() or DateValue() functions so you return a DateTime value instead of a string. You should also be using the AfterUpdate event of the ComboBox rather than the OnClick event. You might also look at a Select Case structure for your code rather than a bunch of If...ElseIf code.
Here's a link you might find useful: A plethora of date functions
 
Also, why not have a 2 column combo where the first hidden field is the numeric month? Then you don't need the If/Then or Select/Case structure. The first day of the month is 1 plus the combo value and the year value. Then use that with the functions referenced by RG to get the last day of the month.
 
Thanks for the advice - I'll do some more reading on the subject using the link you posted.

Confused about Paul's advice - but I expect it will be clearer to me once I sit down with a clear head!
 
Last edited:
Proper format of date

Use proper format of date.
as i had use the following code of line in my program:
Me.txtToDate = GetMonthDays(Month(Me.txtFromDate)) & "-" & _
Month(Me.txtFromDate) & "-" & _
Year(Me.txtFromDate)
and it diplays date like; 31-Aug-07.
Try it!
 
Hint for the enddate: its the first of next month -1 day. Never misses.
 
i can tell you guys this much, that a while ago i was trying to use the DatePiker and i had a lot of problems with customizing it. i was told that i should rather use a good date picker that were made up by others. i am since then using a date picker i found on the internet and it works fine. i even fine tuned it. i think mine is actually from the access text book and i its probably not legal to post it here. but i am sure you can find similar ones.

good luck,

sam
 
Something better for First and Last Day of Month

for first day of month:
txtFirstDay = DateSerial(Year(txtDate), Month(txtDate), 1)
and for last day of month:
txtLastDay = DateSerial(Year(txtDate), Month(txtDate) + 1, 0)
 

Users who are viewing this thread

Back
Top Bottom