Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calendar Controls and Query

Status
Not open for further replies.

EBGreen

Programmer
Apr 1, 2004
2,867
US
I am trying to create a query that uses the values of two calendar controls as between criteria. If I hard code a date for the between criteria, the query runs fine even from the form. If I try to use this for the criteria:
Between [Forms]![MonthlyReport]![txt_StartDate] And [Forms]![MonthlyReport]![txt_StopDate]
Then the sub that is actually running the query (I want to get the results into a recordset) throws an invalid SQL statement error. Any help would be great.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Try changing
Between [Forms]![MonthlyReport]![txt_StartDate] And [Forms]![MonthlyReport]![txt_StopDate]
to
Between # & Forms!MonthlyReport!txt_StartDate & # And # & Forms!MonthlyReport!txt_StopDate & #


Randy
 
When I try that, it won't even let me enter it. I get the
'The expression you entered has an invalid date expression'
error.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Thanks for the help. Here is the SQL:
Code:
SELECT dbo_PRODUCT.PRODUCT_ID, dbo_PRODUCT.MANUFACTURE_ID, dbo_PRODUCT.PRODUCT, dbo_PRODUCT.VERSION, dbo_EMPLOYEE_INFORMATION.LAST_NAME, dbo_EMPLOYEE_INFORMATION.FIRST_NAME, dbo_AB_RELEASE_STATUS.SEQUENCE, dbo_AB_RELEASE_STATUS.DESCRIPTION, dbo_AB_LIFE_CYCLE.DESCRIPTION, dbo_AB_LIFE_CYCLE.LIFE_CYCLE_ID
FROM (((dbo_PRODUCT INNER JOIN dbo_RELEASE_PROCESS_STATUS ON dbo_PRODUCT.PRODUCT_ID = dbo_RELEASE_PROCESS_STATUS.PRODUCT_ID) INNER JOIN dbo_AB_RELEASE_STATUS ON dbo_RELEASE_PROCESS_STATUS.RELEASE_STATUS_CODE = dbo_AB_RELEASE_STATUS.RELEASE_STATUS_CODE) INNER JOIN dbo_EMPLOYEE_INFORMATION ON dbo_RELEASE_PROCESS_STATUS.LOGIN_ID = dbo_EMPLOYEE_INFORMATION.LOGIN_ID) INNER JOIN dbo_AB_LIFE_CYCLE ON dbo_PRODUCT.LIFE_CYCLE_ID = dbo_AB_LIFE_CYCLE.LIFE_CYCLE_ID
WHERE (((dbo_AB_LIFE_CYCLE.LIFE_CYCLE_ID)=1 Or (dbo_AB_LIFE_CYCLE.LIFE_CYCLE_ID)=2 Or (dbo_AB_LIFE_CYCLE.LIFE_CYCLE_ID)=4) AND (([dbo_AB_RELEASE_STATUS]![SEQUENCE])=2.1 Or ([dbo_AB_RELEASE_STATUS]![SEQUENCE])=3.5) AND ((dbo_RELEASE_PROCESS_STATUS.CREATION_DATE) Between [Forms]![MonthlyReport]![txt_StartDate] And [Forms]![MonthlyReport]![txt_StopDate]));

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
OK, I think the problem is in the way I call the query. Here is the code that calls it:
Code:
Dim myRs As New ADODB.Recordset
myRs.Open "Metrics_Test", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Where "Metrics_Test" is the name of the query.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
I've found opening stored queries in ADO with parameters to be a bit challenging. Two methods I use:
1 - concatinate an sql string - or
2 - use the parameters collection of the command object. Now, there might be some challenges there too in Access, have a look at thread709-819033.

Roy-Vidar
 
I found a solution. I pulled the SQL out of the stored query and concat it into a string with my params. Thanks for the help.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top