"Print this record"?

  • Thread starter StargateFanFromWork
  • Start date
S

StargateFanFromWork

How would we approach printing just a record, pls?

I can set up a simple report somehow that shows just the plain text for a
record but wondering what code I'd be looking at that would just print that
one-record type of report.

Or is there a better way? Perhaps there is already something built-in to
A2K?

Pls advise. Thanks! :eek:D
 
F

fredg

How would we approach printing just a record, pls?

I can set up a simple report somehow that shows just the plain text for a
record but wondering what code I'd be looking at that would just print that
one-record type of report.

Or is there a better way? Perhaps there is already something built-in to
A2K?

Pls advise. Thanks! :eek:D

Your table should have a unique prime key field.

After the report has been made, code the command button's Click event:

DoCmd.OpenReport "ReportName", acViewPreview, , "[RecordID] = " &
[RecordID]

The above assumes a [RecordID] field that is a Number Datatype.

If [RecordID] is Text Datatype, then use:

"[RecordID] = '" & [RecordID] & "'"

as the Where clause.
Change the field name to whatever the actual field name is that you
are using.

See Access Help files for:
Where Clause + Restrict data to a subset of records'
 
S

StargateFanFromWork

fredg said:
On Tue, 20 Dec 2005 17:06:00 -0500, StargateFanFromWork wrote:
[snip]
I can set up a simple report somehow that shows just the plain text for a
record but wondering what code I'd be looking at that would just print that
one-record type of report.
[snip]

Your table should have a unique prime key field.

My actual db does, as well as the Northwind example I used below, I imagine.
After the report has been made, code the command button's Click event:

DoCmd.OpenReport "ReportName", acViewPreview, , "[RecordID] = " &
[RecordID]

The above assumes a [RecordID] field that is a Number Datatype.

If [RecordID] is Text Datatype, then use:

"[RecordID] = '" & [RecordID] & "'"

as the Where clause.
Change the field name to whatever the actual field name is that you
are using.

See Access Help files for:
Where Clause + Restrict data to a subset of records'

Thank you so much for the info.

I did a silly thing, I posted this msg before googling the archives which
I'm almost always in the habit of doing now <sigh>. Sorry 'bout that. I
did google after posting and looked and found quite a few posts outlining
very similar-looking code. I can't wrap my brain around the above, somehow,
though <g>. Sorry to say that, but it's true <lol>. I did find reference
to an article in the KB that helps with this as it gives explicit
instructions that were easy to follow:

(The archive page suggesting the KB article is this one:
http://groups.google.ca/group/micro...eba4e7?q=print+record&rnum=9#09f2d6f9bdeba4e7
..)

The KB article we're re-directed to from that page is here:
http://support.microsoft.com/default.aspx?scid=KB;EN-US;209560

I was able to install the sample files so now have Northwind here at work.

I put the button and code to print one record, the one we're looking at at
that moment and everything works well except for one thing, the code takes
you to preview the report and you have to click the printer icon to print
it. In other words, it's too manual. Those are two extra steps that aren't
needed. Is there a way to just print this report automatically without
previewing once the button is pushed? If that could be done then this would
be exactly what I need.

Here is the code as given that does the preview thing:
********************************************
Private Sub cmdPrintRecord_Click()

Dim strReportName As String
Dim strCriteria As String

strReportName = "rptPrintRecord"
strCriteria = "[CustomerID]='" & Me![CustomerID] & "'"
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

End Sub
********************************************

Thank you!
 
S

StargateFanFromWork

StargateFanFromWork said:
[snip]

I put the button and code to print one record, the one we're looking at at
that moment and everything works well except for one thing, the code takes
you to preview the report and you have to click the printer icon to print
it. In other words, it's too manual. Those are two extra steps that aren't
needed. Is there a way to just print this report automatically without
previewing once the button is pushed? If that could be done then this would
be exactly what I need.

Here is the code as given that does the preview thing:
********************************************
Private Sub cmdPrintRecord_Click()

Dim strReportName As String
Dim strCriteria As String

strReportName = "rptPrintRecord"
strCriteria = "[CustomerID]='" & Me![CustomerID] & "'"
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

End Sub
********************************************

I think I got it. I really didn't think I'd figure it out but it seems to
be working. I guess I'm always just a bit amazed when I manage to get
something to work that seems this complicated.

I created the report in the actual db (vs. the example Northwind). Rather
than the complicated code for Northwind, now that I'd tried that example and
could see working code, felt I could try to modify what you so kindly
posted. Mine looks like this now:

********************************************
Private Sub PrintRecord_Click()

DoCmd.OpenReport "ReportPrintRecord", acViewNormal, , "[DocketID] = " &
[DocketID]

End Sub
********************************************

I saw in help, now that I could plug in code name to look for <g>, that
"acViewNormal" would use report without previewing it (vs. "acViewPreview")
and that it would print directly. That seems to be the case. I just click
on printer icon and a printout of the currently-viewed record is generated.
This is _exactly_ what I needed. Is it really as easy as this? <g>

I can't say enough how valuable the help in this ng is. I just don't know
what I'd do without the group, so a big _thank_you_ once again!
 
F

fredg

StargateFanFromWork said:
[snip]

I put the button and code to print one record, the one we're looking at at
that moment and everything works well except for one thing, the code takes
you to preview the report and you have to click the printer icon to print
it. In other words, it's too manual. Those are two extra steps that aren't
needed. Is there a way to just print this report automatically without
previewing once the button is pushed? If that could be done then this would
be exactly what I need.

Here is the code as given that does the preview thing:
********************************************
Private Sub cmdPrintRecord_Click()

Dim strReportName As String
Dim strCriteria As String

strReportName = "rptPrintRecord"
strCriteria = "[CustomerID]='" & Me![CustomerID] & "'"
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

End Sub
********************************************

I think I got it. I really didn't think I'd figure it out but it seems to
be working. I guess I'm always just a bit amazed when I manage to get
something to work that seems this complicated.

I created the report in the actual db (vs. the example Northwind). Rather
than the complicated code for Northwind, now that I'd tried that example and
could see working code, felt I could try to modify what you so kindly
posted. Mine looks like this now:

********************************************
Private Sub PrintRecord_Click()

DoCmd.OpenReport "ReportPrintRecord", acViewNormal, , "[DocketID] = " &
[DocketID]

End Sub
********************************************

I saw in help, now that I could plug in code name to look for <g>, that
"acViewNormal" would use report without previewing it (vs. "acViewPreview")
and that it would print directly. That seems to be the case. I just click
on printer icon and a printout of the currently-viewed record is generated.
This is _exactly_ what I needed. Is it really as easy as this? <g>

I can't say enough how valuable the help in this ng is. I just don't know
what I'd do without the group, so a big _thank_you_ once again!

Good for you!
You figured it out.
Just to add a bit more information about printing without previewing
the report, acViewNormal is the default view, so you could also write:

DoCmd.OpenReport "ReportPrintRecord", , , "[DocketID] = " &
[DocketID]

and it will print directly. Notice you must retain the comma position
if you have additional arguments.
 
S

StargateFan

StargateFanFromWork said:
On Tue, 20 Dec 2005 17:06:00 -0500, StargateFanFromWork wrote:
[snip]

I put the button and code to print one record, the one we're looking at at
that moment and everything works well except for one thing, the code takes
you to preview the report and you have to click the printer icon to print
it. In other words, it's too manual. Those are two extra steps that aren't
needed. Is there a way to just print this report automatically without
previewing once the button is pushed? If that could be done then this would
be exactly what I need.

Here is the code as given that does the preview thing:
********************************************
Private Sub cmdPrintRecord_Click()

Dim strReportName As String
Dim strCriteria As String

strReportName = "rptPrintRecord"
strCriteria = "[CustomerID]='" & Me![CustomerID] & "'"
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

End Sub
********************************************

I think I got it. I really didn't think I'd figure it out but it seems to
be working. I guess I'm always just a bit amazed when I manage to get
something to work that seems this complicated.

I created the report in the actual db (vs. the example Northwind). Rather
than the complicated code for Northwind, now that I'd tried that example and
could see working code, felt I could try to modify what you so kindly
posted. Mine looks like this now:

********************************************
Private Sub PrintRecord_Click()

DoCmd.OpenReport "ReportPrintRecord", acViewNormal, , "[DocketID] = " &
[DocketID]

End Sub
********************************************

I saw in help, now that I could plug in code name to look for <g>, that
"acViewNormal" would use report without previewing it (vs. "acViewPreview")
and that it would print directly. That seems to be the case. I just click
on printer icon and a printout of the currently-viewed record is generated.
This is _exactly_ what I needed. Is it really as easy as this? <g>

I can't say enough how valuable the help in this ng is. I just don't know
what I'd do without the group, so a big _thank_you_ once again!

Good for you!
You figured it out.

(I was wiping the sweat off my brow with this one.) It was a toughie,
even though I'm sure it's all very old hat to the experts here! said:
Just to add a bit more information about printing without previewing
the report, acViewNormal is the default view, so you could also write:

DoCmd.OpenReport "ReportPrintRecord", , , "[DocketID] = " &
[DocketID]

Kewl, so if I've understood correctly, the argument "acViewNormal"
isn't really needed as it's the default so I could leave it out to
accomplish the same thing. Neat.
and it will print directly. Notice you must retain the comma position
if you have additional arguments.

Thank you. :eek:D
 

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