|
Subject:
|
YYYY and MM in access' SQL select statement
|
|
Posted By:
|
Condor76
|
Post Date:
|
2/15/2006 1:31:57 PM
|
I'm new to this forum. I have tried looking for a solution in the net but have not been able to find one. I have the following SQL string in access(SQL View option):
select * from TableName(M200601) where ....
The portion I'm interested in editing is the date: "M200601". This is hard coded right now into the query. I would like for the year and month to be recognized automatically preceded by an M and passes into the Select string. Is there a way to do this?
Thank you for any input provided!
|
|
Reply By:
|
kindler
|
Reply Date:
|
2/15/2006 1:47:24 PM
|
Create a control in which the user selects the month and year they want to view and plugs it into a field, say fldMonth, fldYear; or a fldDate if you keep them combined.
table_name = "M" & fldYear & fldMonth or table_name = "M" & right(fldDate,4) & left(fldDate,2)
Create your query in VBA as: "SELECT * " & _ "FROM " & table_name & " " & _ "WHERE ..."
Should work I think.
Edit: Can also use listboxes to select the Month/Year.
|