Many thanks for the guidance. I've updated the parameter as you suggested.
The query works fine when I run it from the design grid (with the form open
and active) but if I use the query to populate the recordset as part of the
AfterUpdate event on the form:
Set rstIssuesHistory = dbsCurrent.OpenRecordset("Query8")
then I get an error message "Run time error 3061. Too few parameters.
Expected 1"
Can you offer any further advice?
> Access is not understanding the data type correctly.
>
[quoted text clipped - 29 lines]
> >
> > Thanks
That would be right. When the query is run from the Database window, the
Expresssion Service runs and evaluates the parameter from the form. But the
ES does not run in a code context, so the parameter is not evaluated.
Option 1: Explain to Access how to get the parameter value before you
OpenRecordset:
Dim qdf As QueryDef
Set qdf = dbsCurrent.QueryDefs("Query8")
qdf.Parameters("[Forms]![IssueStatus]![CurrentDate]") =
Forms!IssueStatus!CurrentDate
Set rstIssuesHistory = qdf.OpenRecordset
Option 2: Forget the stored query, and create the SQL string dynamically:
Dim strSql As String
strSql = "SELECT Table1.* FROM Table1 WHERE MyDateField = #" & _
Format(Forms!IssueStatus!CurrentDate, "mm/dd/yyyy") & "#;"
Set rstIssuesHistory = dbsCurrent.OpenRecordset(strSql)

Signature
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
> Many thanks for the guidance. I've updated the parameter as you suggested.
>
[quoted text clipped - 43 lines]
>> >
>> > I can't work out why this is happening and would appreciate any help.