Printing only the current record on a report

B

Belinda7237

I have created a report and a command button to preview and then print the
current record of a report. Originally it previewed the report, however it
keeps showing the wrong record and not the current record.

Here is my code I then tried and its still not working:

DoCmd.OpenReport "Individual Package Peer Review Summary", acViewPreview
"[stats Package Number] like '" & Me![stats Package Number] & "'"

The stats package number is the unique identifier for the records.

Any help is appreciated.
 
T

Tom Wickerath

Hi Belinda,

Try replacing the LIKE keyword with an equals sign, like this:

DoCmd.OpenReport "Individual Package Peer Review Summary", acViewPreview
"[stats Package Number] = '" & Me.[stats Package Number] & "'"

The LIKE keyword is used with a wildcard character, which you did not
include. Also, your current use indicates that the stats Package Number field
is a text data type. Is this true? I also recommend that use the "dot"
(period) notation in place of the "bang" (exclaimation mark) notation. The
reason is that the bang method will not pick up a naming error by compiling
your code (Debug | Compile ProjectName).


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
B

Belinda7237

Thanks, very helpful - The stats package number is a number field. Does that
mean that I should use quotes "(stats Package Number)"?

Tom Wickerath said:
Hi Belinda,

Try replacing the LIKE keyword with an equals sign, like this:

DoCmd.OpenReport "Individual Package Peer Review Summary", acViewPreview
"[stats Package Number] = '" & Me.[stats Package Number] & "'"

The LIKE keyword is used with a wildcard character, which you did not
include. Also, your current use indicates that the stats Package Number field
is a text data type. Is this true? I also recommend that use the "dot"
(period) notation in place of the "bang" (exclaimation mark) notation. The
reason is that the bang method will not pick up a naming error by compiling
your code (Debug | Compile ProjectName).


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

Belinda7237 said:
I have created a report and a command button to preview and then print the
current record of a report. Originally it previewed the report, however it
keeps showing the wrong record and not the current record.

Here is my code I then tried and its still not working:

DoCmd.OpenReport "Individual Package Peer Review Summary", acViewPreview
"[stats Package Number] like '" & Me![stats Package Number] & "'"

The stats package number is the unique identifier for the records.

Any help is appreciated.
 
B

Belinda7237

I cut and paste the code and am getting a syntax error - i then inserted the
quotes and got another error. I am sorry I am such a novice, but what do you
think I am doing wrong?

Tom Wickerath said:
Hi Belinda,

Try replacing the LIKE keyword with an equals sign, like this:

DoCmd.OpenReport "Individual Package Peer Review Summary", acViewPreview
"[stats Package Number] = '" & Me.[stats Package Number] & "'"

The LIKE keyword is used with a wildcard character, which you did not
include. Also, your current use indicates that the stats Package Number field
is a text data type. Is this true? I also recommend that use the "dot"
(period) notation in place of the "bang" (exclaimation mark) notation. The
reason is that the bang method will not pick up a naming error by compiling
your code (Debug | Compile ProjectName).


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

Belinda7237 said:
I have created a report and a command button to preview and then print the
current record of a report. Originally it previewed the report, however it
keeps showing the wrong record and not the current record.

Here is my code I then tried and its still not working:

DoCmd.OpenReport "Individual Package Peer Review Summary", acViewPreview
"[stats Package Number] like '" & Me![stats Package Number] & "'"

The stats package number is the unique identifier for the records.

Any help is appreciated.
 
T

Tom Wickerath

Hi Belinda,

Remove the single quotes. Those would only be used if the value you are
passing was text.

DoCmd.OpenReport "Individual Package Peer Review Summary", acViewPreview
"[stats Package Number] = " & Me.[stats Package Number]


Save the changes. Then make sure to click on Debug | Compile ProjectName,
where ProjectName is the name of your VBA project.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
B

Belinda7237

Feeling like an idiot, but still getting an error message indicating that its
expecting a line or end of statement

Private Sub DAReport54_Click()
DoCmd.OpenReport "Individual Package Peer Review Summary", acViewPreview
"[Stats Package Number] = " &Me.[Stats Package Number]

End Sub


Tom Wickerath said:
Hi Belinda,

Remove the single quotes. Those would only be used if the value you are
passing was text.

DoCmd.OpenReport "Individual Package Peer Review Summary", acViewPreview
"[stats Package Number] = " & Me.[stats Package Number]


Save the changes. Then make sure to click on Debug | Compile ProjectName,
where ProjectName is the name of your VBA project.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

Belinda7237 said:
I cut and paste the code and am getting a syntax error - i then inserted the
quotes and got another error. I am sorry I am such a novice, but what do you
think I am doing wrong?
 
J

John W. Vinson

Feeling like an idiot, but still getting an error message indicating that its
expecting a line or end of statement

Private Sub DAReport54_Click()
DoCmd.OpenReport "Individual Package Peer Review Summary", acViewPreview
"[Stats Package Number] = " &Me.[Stats Package Number]

Trapped by word wrap - that should all be on one line, with another comma.
Using the line continuation character _ it would be

DoCmd.OpenReport "Individual Package Peer Review Summary", acViewPreview, _
"[Stats Package Number] = " & Me![Stats Package Number]

If Stats Package Number is a Text field you need some syntactically required
quotemarks:

DoCmd.OpenReport "Individual Package Peer Review Summary", acViewPreview, _
"[Stats Package Number] = '" & Me![Stats Package Number] & "'"

For readability (don't actually do it this way) that's

"[Stats Package Number] = ' " & Me![Stats Package Number] & " ' "
 
T

Tom Wickerath

Good catch John. Belinda recently stated that "The stats package number is a
number field". Not sure if you saw her posting to that effect.

I completely missed the lack of a comma after the acViewPreview part. I
believe two commas are actually needed, since the last positional argument
appears to be a WhereCondition clause.

So, Belinda, with proper commas and line continuation characters, try the
following:

DoCmd.OpenReport _
"Individual Package Peer Review Summary", _
acViewPreview,, _
"[stats Package Number] = " & Me.[stats Package Number]

or, better yet, use named arguments instead of relying on positional
arguments which MUST be separated with the proper number of commas. Named
arguments are also more "readable". For example:

DoCmd.OpenReport _
ReportName:="Individual Package Peer Review Summary", _
View:=acViewPreview, _
WhereCondition:="[stats Package Number] = " _
& Me.[stats Package Number]



Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
B

Belinda7237

Thanks, almost there, but I am getting a new message run time 438 object
doesnt support this property or method. I set this up using a command button
and just put this code under neith it.

Tom Wickerath said:
Good catch John. Belinda recently stated that "The stats package number is a
number field". Not sure if you saw her posting to that effect.

I completely missed the lack of a comma after the acViewPreview part. I
believe two commas are actually needed, since the last positional argument
appears to be a WhereCondition clause.

So, Belinda, with proper commas and line continuation characters, try the
following:

DoCmd.OpenReport _
"Individual Package Peer Review Summary", _
acViewPreview,, _
"[stats Package Number] = " & Me.[stats Package Number]

or, better yet, use named arguments instead of relying on positional
arguments which MUST be separated with the proper number of commas. Named
arguments are also more "readable". For example:

DoCmd.OpenReport _
ReportName:="Individual Package Peer Review Summary", _
View:=acViewPreview, _
WhereCondition:="[stats Package Number] = " _
& Me.[stats Package Number]



Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

John W. Vinson said:
Trapped by word wrap - that should all be on one line, with another comma.
Using the line continuation character _ it would be

DoCmd.OpenReport "Individual Package Peer Review Summary", acViewPreview, _
"[Stats Package Number] = " & Me![Stats Package Number]

If Stats Package Number is a Text field you need some syntactically required
quotemarks:

DoCmd.OpenReport "Individual Package Peer Review Summary", acViewPreview, _
"[Stats Package Number] = '" & Me![Stats Package Number] & "'"

For readability (don't actually do it this way) that's

"[Stats Package Number] = ' " & Me![Stats Package Number] & " ' "
 
T

Tom Wickerath

Hi Belinda,

Does your VBA code compile without any errors (Debug | Compile ProjectName)
when in the VBA Editor?

If you can, please send me a compacted and preferably zipped copy of your
database. If any data is sensitive, then take a copy of your database and
delete the records from the table first, do a compact and repair, and then
send it to me. My e-mail address is available at the bottom of the
contributor's page indicated below. Please do not post your e-mail address
(or mine) to a newsgroup reply. Doing so will only attract the unwanted
attention of spammers.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 

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