Setting a date field using combo box

R

RussCRM

I want to use a combo box with a list of months to set a date range to
two text boxes, txtStartDate and txtEndDate.
My combo box (cboMonth) has two columns, one with a number for the
month such as 1 (for January), 2 ( for February), 3 (for March), etc.
The other column is the month name, which is the visible column. I
also have a cboYear box with the year. When the user selects a month
in cboMonth, I want to set the date range (used by a query/form) to
the date range for that month. However, when I select January, I get
12/1/2007 to 12/31/2007 and 1/1/2008 and 1/31/2008 for all the other
months. Am I doing something wrong?

Here's my code in the AfterUpdate for my cboMonth box:

txtStartDate = DateSerial([cboYear], Month([cboMonth]), 1)
txtEndDate = DateSerial([cboYear], Month([cboMonth]) + 1, 0)
 
K

Klatuu

A date always requires a month, year, and day.
If your query is expecting an date, that that is what you need to use. If
not, please post back with what the query is expecting and we can help find a
way to set it up correctly.
 
R

RussCRM

Basically, my query is looking for records with a date "Between
[Forms]![My Form]![txtStartDate] And [Forms]![My Form]![txtEndDate]"

The query runs fine when there are valid dates in the txtStartDate and
txtEndDate fields. My challenge is how to get those fields to fill
in automatically when a month is selected from a combo box.
 
R

RussCRM

Duh, I have no idea why I was even using the Month() in the
DateSerial. My cboMonth is an integer representing the month number.
The Month() is unnecessary. It should be:

txtStartDate = DateSerial([cboYear], [cboMonth], 1)
txtEndDate = DateSerial([cboYear], [cboMonth] + 1, 0)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top