I have a database and one of the fields is a date field. I would like to be able to select records for my combobox using only a 4 position year. If that year appears in the date, then I would like the record to show in my combobox.
I tried it and all I got was a single record which was the very first record on the database.
This is what I am using:
SELECT [Tournaments].[TNameDateTime]
FROM Tournaments
WHERE Format([Tournaments].[TDate],"yyyy"="' & Selection![YearSel] & '";
The single quotes are enclosed inside of the double quotes. This is a query for the RowSource of my combobox.
If I use an actual date(ie. '2003') it works better but not perfect. The combobox shows the first record on the database(which is a 2002 date) and when I do a pulldown, it shows all 2003 dates.
No matter what I do, I can't get it to work when using a field that is on a form. I even tried to use a Public field and moved my form entry to it. That didn't work either.
I missed the WHERE clause problem, you are selecting TNameDateTime from the table and using TDate in the WHERE clause. This should be TNameDateTime, too.
SELECT [Tournaments].[TNameDateTime]
FROM Tournaments
WHERE Year([Tournaments].[TNameDateTime])="' & Forms!Selection![YearSel] & '";
Anthony J. DeSalvo
President - ScottTech Software
"Integrating Technology with Business"
TNameDateTime is a String field containing a Name concatenated with a Date concatenated with a Time. This is what I want to show in the combobox. Date is another field in my database that I'm trying to filter on. Is this not possible?
This code is already in a query. My Rowsource points to the query name. I've shown the value of the field in a Msgbox in the "on current" vba code, so I know it contains the correct value. As I said before, this works if I use a hard-coded date.
It now works just as if I entered a hard-coded date. It also responds as I indicated before. The combobox shows the 1st record in my database. When I do a pull-down, it shows me only the years that I am looking for. Is there a way to get the initial combobox setting to show the 1st record of the year that I selected instead of the very 1st record in the database?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.