"Michael Israel" <mb***@spamlessoptonline.net> wrote in
news:og*********************@news4.srv.hcvlny.cv.n et:
I am new to Access. I have a form with a single record. The
keyed field is PropID (number). I want to run a query from
the form that will have the current value of PropID be the
variable in the criteria of the query. The intent being the
query returns the values of the current record of the form
for a report. So, I want to code a pushbutton to run that
query with the current keyed field value as the criteria and
then open a report based on that query. How do I do this in
Access. I can do this in other desktop RDBM programs.
Rather than put the query criteria in the recordsource of the
report, you can call the Docmd.openreport method with an optional
WHERE clause that filters the report recordsource.
So in the report calling code, first set up your criteria, then
pass that asa follows
Private sub CmdReportPvw_OnClick ()
Dim stReportname as string
Dim stwhereclause as string
streportname = "MyReport"
stwhereclause = "PropID = " & me.PropID ' For numeric ID
stwhereclause = "PropID = " & chr(34)& me.PropID & me.chr(34) '
For characeter ID
DoCmd.OpenReport streportname, , ,stwhereclause
End sub.
Bob Quintal