From date to End date query not working

djossh

Registered User.
Local time
Today, 11:56
Joined
Oct 19, 2011
Messages
89
Hi.. I have this code which I copied from other tutorials.... but I really don't know what's wrong with my date "From" & "End" query.. it's not giving the right results. Please help.. Thanks.



Private Sub openpqrprt_click()
On Error GoTo err_openpqrprt_click
Dim stdocname As String
stdocname = "RprtP&QID"
Dim whereclause As String

If Not IsNull(txtmep) Then
whereclause = "[MEPNumber]='" & txtmep & ""
End If

If Not IsNull(txtPfromDate) Then
If whereclause <> "" Then whereclause = whereclause & "AND"
whereclause = whereclause & "[PassportExpiryDate]>=#" & Format(txtPfromDate, "mm/dd/yyy") & "#"
End If

If Not IsNull(txtPEndDate) Then
If whereclause <> "" Then whereclause = whereclause & "AND"
whereclause = whereclause & "[PassportExpiryDate]<=#" & Format(txtPEndDate, "mm/dd/yyy") & "#"
End If


DoCmd.openreport stdocname, acPreview, , whereclause

Exit_openpqrprt_click:
Exit Sub

err_openpqrprt_click:
MsgBox Err.Description
Resume Exit_openpqrprt_click




End Sub
 
i would put extra spaces in the sql construction, everywhere you have an operator.

I would display the final where clause first to check it.

it may not be a problem with the where clauses. it may be a problem with the report. if the report query say, fails, the report will just nopt open, with an error 2501.

so what error ARE you getting?
 
i would put extra spaces in the sql construction, everywhere you have an operator.

I would display the final where clause first to check it.

it may not be a problem with the where clauses. it may be a problem with the report. if the report query say, fails, the report will just nopt open, with an error 2501.

so what error ARE you getting?

There are NO Error.. but Im getting all transaction results... as if there is no criteria to filter the results .. do i have to write something in the "Criteria" portion of my Query also?? if so.. what should i write??..Thanks

My report is Based on the Query... and my form "Text" box for criteria is linked to my "Query" also..... I dont know if I should write something also in my "Criteria" portion under "PassportExpiryDate" Fields.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom