
Originally Posted by
Dal Jeanis
1) That's why I said it should cause it to open in the database window.
2) "Parameters off the user form." Got it. If the form isn't open, or the fields haven't been set, then that returns nulls, which errors for a missing parameter. That makes total sense from the immediate window.
So, the question is why CurrentDB.OpenRecordset isn't being able to find those parameters, if it's being executed from that form with the parms set.
At this point, I'd tend to be switching my focus to those parms. I'd use temp variables, have the afterupdate of the parm controls on the form setting the value of the temp variables, and before executing the OpenRecordset, check those values and default them to long ago and long from now. I might also clone the query and use a second query that autodefaults using NZ. Something like Between NZ(startdate, #01/01/1900#) And NZ(enddate, #12/31/2100#) and obviously adjust for any required quotes.
I think I see what the problem is (per your help). My ShowData query is running about 8 subquery's to show all of the data in ONE centralized location. When I attempt to run the code, it looks like the VBA is just attempting to execute my ShowData query and not run the subquery's which take the date parameters, and is causing the query to have no data to show.
For example, I have a query that this is the SQL for:
Code:
SELECT COUNT(combinedTable.UserID) As CountOfUID FROM cobinedTable WHERE (((combinedTable.UserID)="RM1219") AND ((combinedTable.LogInDate) Between[forms]![form1]![start]AND [forms]![form1]![end]
If I input parameters on the user form and run my ShowData query all is well, but it seems that when I Select Dates, and attempt to export to Excel that is where the underlying issue ensues.