Im trying to print a report through visual basic. I have used many different codes to accomplish what I want to do, but none of them are quite what I am looking for.
When the report prints, I want the Print dialogue to popup, all the code I have tried just prints to the default printer.
Can anyone help?
9 4487 @damonrulz
One Method that you can use is to: - Populate a Combo or List Box with all Available Printers.
- Select the specific Printer from the Combo/List Box that will Print the Report.
- Open the Report in Preview Mode and Hidden.
- Set the Report's Printer Object to the chosen Printer.
- Print the Report.
- Close the Report.
Ok, but how do I make the system know that the values in the list are linked to the printers?
@damonrulz
but how do I make the system know that the values in the list are linked to the printers?
Not exactly sure what you mean, please explain.
Well you said make a combo box with the names of the printers in it. How does the system know what that combo box means?
In the code to print, is there a part that looks up the printer form that combo box?
is there a part that looks up the printer form that combo box?
Yes, Items 2 thru 4 in Post #2. Do you need to see the code?
Do you need to see the code?
Yes, I am not very good at writing VB
@damonrulz - Create a Combo Box on your Form and Name it cboPrinters. This Combo Box will contain a listing of all available Printers on your System.
- Copy and Paste the following code to the Open() Event of your Form. It will populate cboPrinters with the List of available Printers previously mentioned.
- Private Sub Form_Open(Cancel As Integer)
-
Dim prn As Printer
-
Dim cbo As ComboBox
-
-
Set cbo = Me![cboPrinters]
-
-
cbo.RowSourceType = "Value List"
-
-
For Each prn In Application.Printers
-
cbo.AddItem prn.DeviceName
-
Next
-
End Sub
- Copy and Paste the following code wherever you deem appropriate, the Click() Event of a Command Button will probably be a good choice. This code will print a Report (rptTest) with the specific Printer you selected from the Combo Box. Set the Value of the Constant conREPORT_TO_PRINT to your Report Name.
- 'Substitute your Report Name here
-
Const conREPORT_TO_PRINT As String = "rptTest"
-
-
'Must select a Printer, correct?
-
If IsNull(Me![cboPrinters]) Then
-
MsgBox "No Printer selected"
-
Exit Sub
-
End If
-
-
'Imperative, Row Source Type must = "Value List"
-
Me![cboPrinters].RowSourceType = "Value List"
-
-
DoCmd.OpenReport conREPORT_TO_PRINT, acViewDesign, , , acHidden
-
-
'Have your Report sent to a specific, selected, Printer
-
Set Reports(conREPORT_TO_PRINT).Printer = Application.Printers.Item(Me![cboPrinters].Value)
-
-
'Fire away!
-
DoCmd.OpenReport conREPORT_TO_PRINT, acViewNormal
-
-
DoCmd.Close acReport, conREPORT_TO_PRINT
- I'm making the assumption that your Access Version is at least 2002, if not, the above code will not work.
When I try to print it comes up with an error:
"This document was previously formatted for the printer on 'Printer Name', but that printer isn't available. Do you want to use the default printer 'Default Printer Name'?"
Then I can click 'OK', 'Cancel', 'Setup', or 'Help'. If i click OK, then the report prints to the deafult printer.
This happens even if the deafult printer is selected in the combo box.
Any ideas?
@damonrulz
This is probably because your Report was previously assigned to a Printer which does not currently exist or is unavailable, try: - In Report ==> Design View
- File ==> Print
- Set the Printer Name = the Default Printer
- Click Open
- Now, execute the code
Sign in to post your reply or Sign up for a free account.
Similar topics
by: DCraig |
last post by:
I'm having problems printing to a line printer from both Crystal Reports and
SQL Server reporting services using dotnet. When I try and print a report
from an application with Crystal I get the...
|
by: DBQueen |
last post by:
I have a database which will be printing out labels for SMALL test tubes
(1/4" high). We have yet to find a reasonably-priced printer (labelwriter)
which can effectively print this on ROLLS of...
|
by: Siv |
last post by:
Hi,
I am getting into printing with VB.NET 2005 and want to implement the usual
capability that a user can select a selection of pages. I have a report
that is generated by my application that if...
|
by: Ron |
last post by:
Hi,
I know Access allows for easy construction of a report setup to print labels
from a table/query, etc. I've done that one. It works pretty well for what
I need.
However, is there an...
|
by: John Smith |
last post by:
Hello, I have 7 different crystal reports that need to be collated.
Since I want to end up with a page of each (which all together make a
single report), I created a blank main report and then...
|
by: Brad Pears |
last post by:
I have a vb.net 2005 application and am using the print preview screen. This screen has a printer icon on it that the user can use to print the document currently being viewed. It uses the default...
|
by: Brett |
last post by:
I have an ASP.NET page that displays work orders in a GridView. In that
GridView is a checkbox column. When the user clicks a "Print" button, I
create a report, using the .NET Framework printing...
|
by: Deceneu |
last post by:
Hi everyone, this is my first post so please bear with me.
I have the following situation: i have a local report that needs to have two "versions": one for viewing in the report viewer (with all...
|
by: Glenn |
last post by:
I am writing a program for field work that will use a receipt
printer. I need to be able to adjust the page settings prior to
printing depending on how much needs to be printed. I have been able...
|
by: it0ny |
last post by:
Hi guys,
thanks I am fairly new to this forum so I hope I chose the right place to post this question.
I try to make my program printout a deposit's report. I created a class to store the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |