Printing one report

A

access wiz

I am completely stumped, I have searched the community on how to get this
accomplished and have yet to find the answer. I have 83 records, I have
prepared a report which is unique to each individual record, I do now want to
print out 83 records at a time, I simply want to print record 53 or 62 or 71.
I have created a command button on my form which prints out records, I have
attempted to input such code as:

DoCmd.OpenReport "YourReport", acPreview
Reports![YourReport].Filter = "YourPrimaryKey = " & Me![YourPrimaryKeyControl]
Reports![YourReport].FilterOn = True


or

me.Refresh
docmd.OpenReport "myReprot",acViewPreview,,"id = " & me!id

and it opens the print preview screen starting with record/ID 1, when it
should be displaying record/ID 42 or 71, etc... The key for both the report
and form is the ID. How do I go about printing a report 52 for form 52?


Thanks
 
F

fredg

I am completely stumped, I have searched the community on how to get this
accomplished and have yet to find the answer. I have 83 records, I have
prepared a report which is unique to each individual record, I do now want to
print out 83 records at a time, I simply want to print record 53 or 62 or 71.
I have created a command button on my form which prints out records, I have
attempted to input such code as:

DoCmd.OpenReport "YourReport", acPreview
Reports![YourReport].Filter = "YourPrimaryKey = " & Me![YourPrimaryKeyControl]
Reports![YourReport].FilterOn = True

or

me.Refresh
docmd.OpenReport "myReprot",acViewPreview,,"id = " & me!id

and it opens the print preview screen starting with record/ID 1, when it
should be displaying record/ID 42 or 71, etc... The key for both the report
and form is the ID. How do I go about printing a report 52 for form 52?

Thanks


Why Me.Refresh?

All you need do is use the Where clause argument of the OpenReport
method.


' First save any newly entered data
DoCmd.RunCommand acCmdSaveRecord
' Then open the report
DoCmd.OpenReport "MyReport", acViewPreview, , "[ID] = " & Me![ID]

assuming the prime key field is named [ID], the field datatype is
Number, and the control on the form is named "ID".

If, however, the [ID] field datatype is text, then use

DoCmd.OpenReport "MyReport", acViewPreview, , "[ID] = '" & Me![ID] &
"'"
Change [ID} to whatever the record's prime key field name actually is.
 
S

Steve Schapel

Wiz,

I am surprised that this:
DoCmd.OpenReport "myReprot", acViewPreview, , "ID = " & Me!ID
.... does not work.
 
A

access wiz

Thanks for the input guys.

Steve I was surprised that this didn't work as well, I cannot figure it
out. The table I am working off it not of my own so perhaps the problem lies
there. Just to confirm, how do I go about checking that the Key field is the
ID?

Steve Schapel said:
Wiz,

I am surprised that this:
DoCmd.OpenReport "myReprot", acViewPreview, , "ID = " & Me!ID
.... does not work.

--
Steve Schapel, Microsoft Access MVP

access said:
I am completely stumped, I have searched the community on how to get this
accomplished and have yet to find the answer. I have 83 records, I have
prepared a report which is unique to each individual record, I do now want to
print out 83 records at a time, I simply want to print record 53 or 62 or 71.
I have created a command button on my form which prints out records, I have
attempted to input such code as:

DoCmd.OpenReport "YourReport", acPreview
Reports![YourReport].Filter = "YourPrimaryKey = " & Me![YourPrimaryKeyControl]
Reports![YourReport].FilterOn = True


or

me.Refresh
docmd.OpenReport "myReprot",acViewPreview,,"id = " & me!id

and it opens the print preview screen starting with record/ID 1, when it
should be displaying record/ID 42 or 71, etc... The key for both the report
and form is the ID. How do I go about printing a report 52 for form 52?


Thanks
 
A

access wiz

Funny thing how the answers are some time right in front of you. After
asking you the question about the Key, I went back to the table it was based
upon, the one that wasn't originally mine and discovered that they had never
placed a key in the table. This whole time there was no point of reference.
Regardless, it now works and I can finally rest at ease because I have been
driving myself nuts.

Thanks to the both of you.

access wiz said:
Thanks for the input guys.

Steve I was surprised that this didn't work as well, I cannot figure it
out. The table I am working off it not of my own so perhaps the problem lies
there. Just to confirm, how do I go about checking that the Key field is the
ID?

Steve Schapel said:
Wiz,

I am surprised that this:
DoCmd.OpenReport "myReprot", acViewPreview, , "ID = " & Me!ID
.... does not work.

--
Steve Schapel, Microsoft Access MVP

access said:
I am completely stumped, I have searched the community on how to get this
accomplished and have yet to find the answer. I have 83 records, I have
prepared a report which is unique to each individual record, I do now want to
print out 83 records at a time, I simply want to print record 53 or 62 or 71.
I have created a command button on my form which prints out records, I have
attempted to input such code as:

DoCmd.OpenReport "YourReport", acPreview
Reports![YourReport].Filter = "YourPrimaryKey = " & Me![YourPrimaryKeyControl]
Reports![YourReport].FilterOn = True


or

me.Refresh
docmd.OpenReport "myReprot",acViewPreview,,"id = " & me!id

and it opens the print preview screen starting with record/ID 1, when it
should be displaying record/ID 42 or 71, etc... The key for both the report
and form is the ID. How do I go about printing a report 52 for form 52?


Thanks
 

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