FILTERING

A

AMDGUY [MCP]

I have a querry setup like this

Month
Format([DATE],"MMM" & " " & "YYYY")

data1
group by sum

data2
group by sum

Im trying to use a form to alow the user to filter it but I keep
comming up with an error using this code. Can some one tell me whats
wrong. It will not fiter the date when formated as above.


Private Sub Command16_Click()
Dim db As DAO.Database
Dim qd As QueryDef
Dim where As Variant
Set db = CurrentDb()
On Error Resume Next
db.QueryDefs.Delete ("DATABYMONTHDF")
On Error GoTo 0
where = Null
If Not IsNull(Me![fromdate]) Then
If Not IsDate(Me![fromdate]) Then
MsgBox "The value in from is not a valid date.", _
vbCritical, gstrapptitle
Exit Sub
End If
If Not IsNull(Me![todate]) Then
If Not IsDate(Me![todate]) Then
MsgBox "The value in to is not a valid date.", _
vbCritical, gstrapptitle
Exit Sub
End If
End If
End If
If Not IsNull(Me![todate]) Then
where = where & " and [DATE] between #" + _
Me![fromdate] + "# and #" & Me![todate] & "#"
Else
where = where & " and [MONTH] >= #" + Me![fromdate] + " #"
End If
Set qd = db.CreateQueryDef("DATABYMONTHDF", _
"select * from DATABYMONTH " & (" where " + Mid(where, 6) & ";"))
End Sub
 

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