Print Report for one form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to add a button to a fromt o print a report for that one form.

I am using

Dim stDocName As String
stDocName = "Recipe Cards"
DoCmd.OpenReport stDocName, acPreview, [Recipe] = Forms![Recipe]![Recipe]

Unfortunately too many object in the file are named Recipe. When I do this,
I get the report for all the records. If I hard code it to Say [Recipe] =
"Banana Bread" then the report only prints when I am on the Banana Bread
record. Like it is boolean. If I hard code the restriction in the report on
the filter line [Recipe] = "Banana Bread" it prints just that one record.
This is making me a bit crazy!
 
Hi
Suggest you create a query that uses the recipe number (or whatever is the
primary key on your form) as the criteria for the query. You can use the
builder (right click the mouse in the query criteria cell) to create the
criteria expression. It will be something like [forms]!frmRecipe.RecipeNo
The query will return one record. You can then create a report using that
query that will only print out the record currently displayed on the form
 
Blonde said:
I am trying to add a button to a fromt o print a report for that one
form.

I am using

Dim stDocName As String
stDocName = "Recipe Cards"
DoCmd.OpenReport stDocName, acPreview, [Recipe] =
Forms![Recipe]![Recipe]

First, you want this in the WhereCondition argument, not the FilterName
argument. Second it needs to be in quotes.

DoCmd.OpenReport stDocName, acPreview,, "[Recipe] = Forms![Recipe]![Recipe]"
 
AAAHHH!! Quotes!!! NEither the Microsoft help file nor the article on the
subject indicates the need for quotes. I am never sure when to use quotes in
programing.

ThAnk you!!

Rick Brandt said:
Blonde said:
I am trying to add a button to a fromt o print a report for that one
form.

I am using

Dim stDocName As String
stDocName = "Recipe Cards"
DoCmd.OpenReport stDocName, acPreview, [Recipe] =
Forms![Recipe]![Recipe]

First, you want this in the WhereCondition argument, not the FilterName
argument. Second it needs to be in quotes.

DoCmd.OpenReport stDocName, acPreview,, "[Recipe] = Forms![Recipe]![Recipe]"
 
As long as the field Recipe is a UNIQUE KEY, you won't have a problem.
The idea behind a UNIQUE KEY is to uniquely identify the record for just
such a purpose.
 
Were you actually assuming that Microsoft Help would be helpful? It is
afterall an oxymoron like government assistance and military intelligence.

Blonde said:
AAAHHH!! Quotes!!! NEither the Microsoft help file nor the article on the
subject indicates the need for quotes. I am never sure when to use quotes in
programing.

ThAnk you!!

:

Blonde said:
I am trying to add a button to a fromt o print a report for that one
form.

I am using

Dim stDocName As String
stDocName = "Recipe Cards"
DoCmd.OpenReport stDocName, acPreview, [Recipe] =
Forms![Recipe]![Recipe]

First, you want this in the WhereCondition argument, not the FilterName
argument. Second it needs to be in quotes.

DoCmd.OpenReport stDocName, acPreview,, "[Recipe] = Forms![Recipe]![Recipe]"
 
Blonde CE said:
AAAHHH!! Quotes!!! NEither the Microsoft help file nor the article on the
subject indicates the need for quotes. I am never sure when to use quotes in
programing.

You were probably looking at the help article for the OpenReport *action* rather
than the OpenReport *method* of DoCmd. At least in Access 97 that help topic
clearly indicates that all of the arguments are string expressions except for
the view option.

reportname - A string expression that's the valid name of a report in the
current database.

filtername - A string expression that's the valid name of a query in the current
database.

wherecondition - A string expression that's a valid SQL WHERE clause without the
word WHERE.

(any time it's a string expression it needs to be in quotes)
 
Be careful with those quotes! Let the form reference get evaluated and
append the result to the string.

-- Instead of :

DoCmd.OpenReport stDocName, acPreview,,"[Recipe] = _
Forms![Recipe]![Recipe]"

try:

DoCmd.OpenReport stDocName, acPreview,,"[Recipe] = " & _
Forms![Recipe]![Recipe]


HTH,

Kevin
Blonde said:
AAAHHH!! Quotes!!! NEither the Microsoft help file nor the article on the
subject indicates the need for quotes. I am never sure when to use quotes in
programing.

ThAnk you!!

:

Blonde said:
I am trying to add a button to a fromt o print a report for that one
form.

I am using

Dim stDocName As String
stDocName = "Recipe Cards"
DoCmd.OpenReport stDocName, acPreview, [Recipe] =
Forms![Recipe]![Recipe]

First, you want this in the WhereCondition argument, not the FilterName
argument. Second it needs to be in quotes.

DoCmd.OpenReport stDocName, acPreview,, "[Recipe] = Forms![Recipe]![Recipe]"
 
Back
Top