View Full Version : Passing combo box value to a query


pwdpwd
02-05-2010, 11:28 PM
Hi - would appreciate some help on a criteria issue with a select query:

I know how to pass a value from a text box on a form to a query - that works fine.

What I want to do now is to pass the value from a combo box to a query. I have a table which stores the year (yyyy) and a yearstartdate (dd/mm/yy) - which is not always 1st January. I have bound the combo box to that table, and disply the year only

I want the user to select the year from the combo box, but to pass the value for the date to the query.

Is there a way of doing this?

John Big Booty
02-06-2010, 12:09 AM
Use;
Forms!FRM_FormName!ComboName
as the criteria in your query. This will pass the currently selected value in the combo to your query.

pwdpwd
02-08-2010, 12:29 AM
Hi - thanks, but when I do that I get an error.

What I'm trying to do is to select service dates within a 53 week year. When I use specific criteria in the ServiceDate field in the query (dd/mm/yyyy) to

"Between #28/12/2009# And (#28/12/2009#+371)"

it works fine.

When I use a text box (set to dd/mm/yyyy) and set the criteria to

"Between Forms!FRM_FormName!TextBox and (Forms!FRM_FormName!TextBox +371)"

it also works fine

I bound a combo box to the tbltablestartdate, which has 3 fields - ID, year and yearstartdate. I want to let the user select the year (yyyy) but use the yearstartdate (dd/mm/yyyy) as the criteria in the query. Using the criteria that you suggested gives the error, presumably because it's passing the year - the field selected - into a dd/mm/yyy criteria.

Any ideas?

GalaxiomAtHome
02-08-2010, 12:53 AM
It is extremely unlikely you need to store a year startdate in a table.
Access has date functions to calculate anything you care to imagine.

Check out some of the date functions indexed on this page.

http://www.techonthenet.com/access/functions/index.php

John Big Booty
02-08-2010, 01:07 AM
The formula I gave in my previous post passes the bound column of the combo to the query, which is why you are getting an error from your query.