Open report in Filter asks for Parameter Value

J

John

I am trying to open a report filtered to a particular RM (text field) from a
"dashboard" which is a continous form. PEPRM is the PKey field. I have the
following code in the 'on double click' event for the PEPRM field:

DoCmd.OpenReport "rptPEPs", acViewPreview, , "PEPRM = " & Me!PEPRM

I still get a pop up asking for the parameter value. If I enter nothing,
the report is blank, if I enter the PEPRM's ID (same as the value in the
PEPRM fields), it returns what I would expect. Why is the filter not working?

Thanks
 
A

Allen Browne

Several things could be happening.

Firstly, open the report in design view, and see if PEPRM is actually in its
RecordSource (the table or query that feeds the report.) If not, attempting
to filter on this field won't work. (I'm not clear on the connection between
RM and PEPRM.)

If you think it's there, but it's not showing on the report, put it on the
report and see if that works. (If it does, you can just set its Visible
property to No and leave it there.)

If that's not the issue, perhaps the form is at a new record, or the record
has not yet been saved. The following code is explained here:
http://allenbrowne.com/casu-15.html

Private Sub cmdPrint_Click()
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[PEPRM] = " & Me.[ID]
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
End If
End Sub
 
J

John

Allen - first - thanks for your help. Second, You states that you were not
clear on the relation between RM and PEPRM. That was my mistake in the post.
There is no RM field it should have read PEPRM.
My report is linked to my table of PEPTargets. This table does have a field
for the PEPRM. This field happens to be a lookup to another table though and
is text. I think my syntax in this code is wrong for text. so...

The code you provided (along with the modification for text PKey provided on
the link) worked great.

Thanks

--
qwerty


Allen Browne said:
Several things could be happening.

Firstly, open the report in design view, and see if PEPRM is actually in its
RecordSource (the table or query that feeds the report.) If not, attempting
to filter on this field won't work. (I'm not clear on the connection between
RM and PEPRM.)

If you think it's there, but it's not showing on the report, put it on the
report and see if that works. (If it does, you can just set its Visible
property to No and leave it there.)

If that's not the issue, perhaps the form is at a new record, or the record
has not yet been saved. The following code is explained here:
http://allenbrowne.com/casu-15.html

Private Sub cmdPrint_Click()
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[PEPRM] = " & Me.[ID]
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

John said:
I am trying to open a report filtered to a particular RM (text field) from
a
"dashboard" which is a continous form. PEPRM is the PKey field. I have
the
following code in the 'on double click' event for the PEPRM field:

DoCmd.OpenReport "rptPEPs", acViewPreview, , "PEPRM = " & Me!PEPRM

I still get a pop up asking for the parameter value. If I enter nothing,
the report is blank, if I enter the PEPRM's ID (same as the value in the
PEPRM fields), it returns what I would expect. Why is the filter not
working?

Thanks
 

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