Print Curent Record From Form on Report

S

Srenfro

Hello,
I have a printing problem with my data base I have a print button that
prints but it prints every record i have but I would like it to only print
one record and be the current one that I am viewing. and i dont want to
preview it eather I want instant print from report. the code in my button is:

Private Sub cmdPrintRecord_Click()
On Error GoTo Err_cmdPrintRecord_Click


DoCmd.RunCommand acCmdSelectRecord
DoCmd.PrintOut acSelection

Exit_cmdPrintRecord_Click:
Exit Sub

Err_cmdPrintRecord_Click:
MsgBox Err.Description
Resume Exit_cmdPrintRecord_Click

End Sub

thank you!
 
F

fredg

Hello,
I have a printing problem with my data base I have a print button that
prints but it prints every record i have but I would like it to only print
one record and be the current one that I am viewing. and i dont want to
preview it eather I want instant print from report. the code in my button is:

Private Sub cmdPrintRecord_Click()
On Error GoTo Err_cmdPrintRecord_Click

DoCmd.RunCommand acCmdSelectRecord
DoCmd.PrintOut acSelection

Exit_cmdPrintRecord_Click:
Exit Sub

Err_cmdPrintRecord_Click:
MsgBox Err.Description
Resume Exit_cmdPrintRecord_Click

End Sub

thank you!

First create a report that displays all of the data you want to show.

Then¡K.

Your table should have a unique prime key field.
In my example it is named [RecordID].


Code a command button's Click event:

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

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

If, however, [RecordID] is Text Datatype, then use:

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

as the Where clause.

For clarity, the single and double quotes are..
"[RecordID] = ' " & [RecordID] & " ' "

Change [RecordID] to whatever the actual field name is that you are
using.

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

The above will preview the report.
To print without preview change acViewPreview to acViewNormal.
 
S

Srenfro

thanks for bolth of your help but the first one from Golfinray only prints my
report with the current record which is much closer than i was and Fredg I
get a compiler error is there a way I can get access to just print my current
record and i am looking at my form and pushing my print button but i want it
to print the report but never show the report. But The current record is
there anyone who can help me thank you
 
F

fredg

thanks for bolth of your help but the first one from Golfinray only prints my
report with the current record which is much closer than i was and Fredg I
get a compiler error is there a way I can get access to just print my current
record and i am looking at my form and pushing my print button but i want it
to print the report but never show the report. But The current record is
there anyone who can help me thank you

We can't see your computer.
Can't help you unless you let us know on what line the compiler error
occurred.
If you have a question about the code, please copy and paste your
exact code into a reply message. Most likely it's a miss-spelled word
or a missing comma or dot.
 
C

Chuck

thanks for bolth of your help but the first one from Golfinray only prints my
report with the current record which is much closer than i was and Fredg I
get a compiler error is there a way I can get access to just print my current
record and i am looking at my form and pushing my print button but i want it
to print the report but never show the report. But The current record is
there anyone who can help me thank you

Base your report on a query that contains all the fields the report uses. Set
the criteria for the invoice number in the query to :
= Forms.your form name.text box name where you enter something that will
reference only the specific record you want to print. Perhaps a Primary Key.

Put a command button on the form that opens the report but does not close the
form..

The report will look at the query for its data. The query will get the filter
data from the form which, although it may be hidden, will still be open.

Chuck
 
S

Srenfro

Private Sub printcmd_Click()
On Error GoTo Err_printcmd_Click

Dim stDocName As String


stDocName = "Enter Contracts"
DoCmd.OpenReport stDocName, acViewNormal, acFilterNormal
DoCmd.PrintOut acSelection
DoCmd.CLOSE


Exit_printcmd_Click:
Exit Sub

Err_printcmd_Click:
MsgBox Err.Description
Resume Exit_printcmd_Click

End Sub

This is the code for my print button and it comes back with cant find "0",
whatever that means? can someone uncover the problem i am having thanks

Stephen
 
C

Chuck

Private Sub printcmd_Click()
On Error GoTo Err_printcmd_Click

Dim stDocName As String


stDocName = "Enter Contracts"
DoCmd.OpenReport stDocName, acViewNormal, acFilterNormal
DoCmd.PrintOut acSelection
DoCmd.CLOSE


Exit_printcmd_Click:
Exit Sub

Err_printcmd_Click:
MsgBox Err.Description
Resume Exit_printcmd_Click

End Sub

This is the code for my print button and it comes back with cant find "0",
whatever that means? can someone uncover the problem i am having thanks

Stephen

Your code looks like you are trying to open a report and immediately print it
without having any time to preview the report.

In A97 the code to print a report is simply:

stDocName = "Enter Contracts"
DoCmd.OpenReport stDocName, acNormal

The report prints immediately to the default printer and never shows on the
screen.

Chuck
 

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