Making a month picker (1 Viewer)

Chrism2

Registered User.
Local time
Today, 07:28
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
 

RuralGuy

AWF VIP
Local time
Today, 00:28
Joined
Jul 2, 2005
Messages
13,825
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
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 23:28
Joined
Aug 30, 2003
Messages
36,137
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.
 

Chrism2

Registered User.
Local time
Today, 07:28
Joined
Jun 2, 2006
Messages
161
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:

adnanahmed

Adnan Ahmed
Local time
Today, 10:28
Joined
Aug 14, 2007
Messages
4
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!
 

Guus2005

AWF VIP
Local time
Today, 08:28
Joined
Jun 26, 2007
Messages
2,642
Hint for the enddate: its the first of next month -1 day. Never misses.
 

SamDeMan

Registered User.
Local time
Today, 02:28
Joined
Aug 22, 2005
Messages
182
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
 

adnanahmed

Adnan Ahmed
Local time
Today, 10:28
Joined
Aug 14, 2007
Messages
4
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

Top Bottom