Filter a report based on a single field in open form

G

Guest

Hi All,

Can someone please tell me why this code is not filtering my report? The
button opens the report but won't filter. FTA_Terr_txtbox is the field on my
main form "Frm_Tap_Accounts". Terr_No_txtbox is the field on my report,
"Compliance_Report".

Private Sub Btn_View_Current_TM_Rpt_Click()
On Error GoTo Err_Btn_View_Current_TM_Rpt_Click

Dim stDocName As String, strLinkCriteria As String

stDocName = "Compliance_Report"
strLinkCriteria = "[Terr_No_txtbox] ='" & Me![FTA_Terr_Txtbox] & "'"

DoCmd.OpenReport stDocName, acPreview, strLinkCriteria

Exit_Btn_View_Current_TM_Rpt_Click:
Exit Sub

Err_Btn_View_Current_TM_Rpt_Click:
MsgBox Err.Description
Resume Exit_Btn_View_Current_TM_Rpt_Click

End Sub

I have also tried:

strLinkCriteria = "[Terr_No_txtbox] =" & Me![FTA_Terr_Txtbox]

for strLinkCriteria, without success.

What am I doing wrong?

Emma
 
M

Marshall Barton

Emma said:
Can someone please tell me why this code is not filtering my report? The
button opens the report but won't filter. FTA_Terr_txtbox is the field on my
main form "Frm_Tap_Accounts". Terr_No_txtbox is the field on my report,
"Compliance_Report".

Private Sub Btn_View_Current_TM_Rpt_Click()
On Error GoTo Err_Btn_View_Current_TM_Rpt_Click

Dim stDocName As String, strLinkCriteria As String

stDocName = "Compliance_Report"
strLinkCriteria = "[Terr_No_txtbox] ='" & Me![FTA_Terr_Txtbox] & "'"

DoCmd.OpenReport stDocName, acPreview, strLinkCriteria


The problem is that you are not using the WhereCondition
argument. Add another comma before strLinkCriteria.
 
G

Guest

What type of field is this Terr_No_txtbox ?

Is it numeric? There may be extra spaces.
Try:
strLinkCriteria = "[Terr_No_txtbox] =" & Trim(Me![FTA_Terr_Txtbox])
Or if it is an integer field:
strLinkCriteria = "[Terr_No_txtbox] =" &
CInt(Trim(Me![FTA_Terr_Txtbox]))

Is it Text? You will need to add single quotes:
strLinkCriteria = "[Terr_No_txtbox] ='" & Trim(Me![FTA_Terr_Txtbox])
& "'"


jmonty
 
G

Guest

That was it . . . .I should have seen it.

Thank you,

Marshall Barton said:
Emma said:
Can someone please tell me why this code is not filtering my report? The
button opens the report but won't filter. FTA_Terr_txtbox is the field on my
main form "Frm_Tap_Accounts". Terr_No_txtbox is the field on my report,
"Compliance_Report".

Private Sub Btn_View_Current_TM_Rpt_Click()
On Error GoTo Err_Btn_View_Current_TM_Rpt_Click

Dim stDocName As String, strLinkCriteria As String

stDocName = "Compliance_Report"
strLinkCriteria = "[Terr_No_txtbox] ='" & Me![FTA_Terr_Txtbox] & "'"

DoCmd.OpenReport stDocName, acPreview, strLinkCriteria


The problem is that you are not using the WhereCondition
argument. Add another comma before strLinkCriteria.
 

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