Pass Date parameters to a Query

G

Guest

I am trying to pass a date range to a query. I copied the following code,
(from Allenbrowne.com), that was used for a report and edited it for a query.
When I run the code I get this error message:"Wrong number of Arguments or
invalid property assignment".
This happens on the last line of the following code: I would welcome any
comments on this.

Private Sub Command15_Click()
Dim strQuery As String 'Name of Query to open.
Dim strField As String 'Name of your date field.
Dim strWhere As String 'Where condition for OpenQuery.
Const conDateFormat = "\#>m<mm\-yy\#"

strQuery = "Qry GL Activity"
strField = "Period_Name"

If IsNull(Me.qStart) Then
If Not IsNull(Me.QEnd) Then 'End date, but no start.
strWhere = strField & " < " & Format(Me.QEnd, conDateFormat)
End If
Else
If IsNull(Me.QEnd) Then 'Start date, but no End.
strWhere = strField & " > " & Format(Me.qStart, conDateFormat)
Else 'Both start and end dates.
strWhere = strField & " Between " & Format(Me.qStart,
conDateFormat) _
& " And " & Format(Me.QEnd, conDateFormat)
End If
End If

' Debug.Print strWhere 'For debugging purposes only.

DoCmd.OpenQuery strQuery, acViewNormal, , strWhere

End Sub
 
D

Douglas J Steele

You sure you copied that correctly? That Date format of "\#>m<mm\-yy\#"
certainly doesn't look correct.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top