Open Report to specific record

G

Guest

In Form I put a button that was wizard to open a Report.

I went into build event for that button and at the DoCmd added a WHERE
condition

was:
DoCmd ReportName, acViewPreview

I changed to:
DoCmd ReportName, acViewPreview, ,"ReportID=" & Me.BillingID

so that the value of textbox (BillingID) of this form is the criteria for
the report to open onto the record that has that same value in it's ReportID
field (based on the equivalent table field)

and it works - except - before the report opens I get a message box prompt
to Enter Parameter and the value of BillingID is showing in the
message box prompt - - - it really looks identical to a standard Parameter
Query message....
 
S

strive4peace

where is the code being executed? Do not call this
procedure in the Open event of the form (the data is not yet
LOADed). do not call it on Load either unless you know ytou
are on a valid record.

In case you are not on a valid (current) record in the form,
change the code to:

DoCmd ReportName, acViewPreview, , _
"ReportID=" & nz(Me.BillingID,0)

if you are not on a valid record, the report will (should)
not return any records

Alternately, you can test for null Me.BillingID before you
render the report

'~~~~~~~~~~~`
'save record
if me.dirty them me.dirty = false

if isnull(me.Me.BillingID) then
msgbox "You do not have a current record" _
,,"Cannot process report"
exit sub
end if
'~~~~~~~~~~~`

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
G

Guest

thanks but still hung up - and yet it seems so easy...:

the Form has a button

the button is to open a Report

the Report is to open at a specific record

the Report's specific record is identified by matching a value in a textbox
in the Form

not worried about exceptions or nulls at this point - am in controlled
situation with my test data and just trying to get the Report Opening with a
correct WHERE command syntax so the Report showing the correct record

here is line am trying:
DoCmd ReportName, acViewPreview, , "ReportID=" & nz(Me.BillingID,0)

am getting error message:
Syntax Error (missing operator) in query expression '(ReportID=455)'

b.t.w. the 455 is the valid value in the textbox which I do want to be the
record when the report opens
 
G

Guest

You may be working too hard. Try writing a query to filter the records to
the one(s) you want, and then add the name of the query to this procedure,
like this:

DoCmd ReportName, acViewPreview, "Queryname"

But if you really need to have that built in, try enclosing your criteria in
quotes - but since you actually need the fieldname, you'll need quotes around
THAT as well. Try this:

DoCmd ReportName, acViewPreview, ,"""ReportID="" & Me.BillingID"

THREE double-quotes. The first and last enclose the criteria expression.
The next two are "literal quotes" around 'ReportID='
 

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