K
K. Hulse
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
(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