Need an explanation on DoCmd

  • Thread starter Thread starter Sandra
  • Start date Start date
S

Sandra

I have a command buttom with a proc that opens a form and
prints a record. This works fine in one form (a nice
person on the forum helped me with this), but when I copy
the code to use in another form I cannot seem to get the
right syntax for the WhereCondition. I don't know if it is
asking for the form name, the table name, the report name
or something else, but nothing I type seems to work.

DoCmd.OpenReport stDocName,
acPreview, , "PeoplePlaces.PPID = " & Me.PPID

Can someone explain these components to me?

Thanks,
Sandra
 
stDocName need to contain the name of the report, e.g.:
stDocName = "YourReportNameHere"

acPreview (or better, acViewPreview) opens the report in preview mode.
Replace it with acViewNormal if you want the report to go directly to the
printer.

The two commas are needed because the "filter" argument is not used.
Instead, the last argument filters the report to just the matching values.

The WhereCondition consist of something like this:
"MyField = 999"
In the example you gave, the field is "PeoplePlaces.PPID" (i.e. the PPID
field from the PeoplePlaces table), and the 999 value is picked up from
whatever is in the text box named "PPID" on the form. ("Me" is a reference
to the form.)

So, if you wanted to open Report45 in preview mode where the ClientID field
equals the value in the text box named "txtClientID", you would use:

stDocName = "Report45"
DoCmd.OpenReport stDocName, acViewPreview, , _
"ClientID = " & Me.txtClientID
 
I don't normally use the qualifier and simply use:

"PPID = " & Me.PPID

Basically, PPID must be in the RecordSource of the Report and the LHS of the
ampersand says:

"For the Report, only select Records that have PPID equal to:"

The RHS specifies the value to use for the selection and in this case, you
specify to use the value of the Field PPID (or a Control "PPID") of the
CurrentRecord in the current Form. For example if Me.PPID = 1 in the
current Form, then your selection criterion for the Report will be:

PPID = 1

Note that the PPID Field must be a numeric Field for your wherecondition to
work. If it is a Text Field, you must enclose the (final) literal value in
single or double quotes.


(For all arguments)

All the arguments are in the Access VB Help topic for the OpenReport Method.
The full syntax is:

DoCmd.OpenReport reportname[, view][, filtername][, wherecondition]

I leave it to you to check out the Help topic for the explanation of the
arguments and the example.

In fact, Access / Access VB Help should be the first resource to use and it
is always handy. You don't have to wait for someone to reply either.
 
Back
Top