Print Report for one form

B

Blonde CE

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!
 
N

NevilleT

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
 
R

Rick Brandt

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]"
 
B

Blonde CE

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]"
 
D

David C. Holley

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.
 
D

David C. Holley

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]"
 
K

Kevin K. Sullivan

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]"
 
Top