Solved

CommonDialog printing

Posted on 1998-06-11
6
169 Views
Last Modified: 2010-05-03
Ok, this is a really simple problem, but I'll be damned if I can get it to work...

OK, I have a text file, called "am.txt" that I want to print from a VB program. I don't want to open it, I just want to print it to the default windows printer.

I've created a form with a Common Dialog box control, and a button. In the click event of the button is the following code:
     commondialog1.filename="c:\am.txt"
     commondialog1.action=5 '//The print dialog

Now, this displays the print dialog, but when I click on OK, nothing happens.

What have I missed?

Dan

p.s The default printer is a networked HP LaserJet 5N.
0
Comment
Question by:FaffMan
6 Comments
 
LVL 6

Expert Comment

by:anthonyc
ID: 1463086
Dan

The common dialog control does not print.....  It sets up printing

use the printer object for printing
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1463087
FaffMan,
The commonDialog only allow you to select the parameters for printing, such as printer, number of copies. It does not actually send the data to the printer. You need to write the code as to how you want your file.
One simple way is to set the PrinterDefault property to true and use the Printer object.
If you have more questions, let me know.
Regards
Dalin
0
 

Author Comment

by:FaffMan
ID: 1463088
OK, so I tried the printer.print method, but I couldn't get that to work either.

If someone can give me some code that will actually print this text file, then I'll up the points to 100.

Dan



0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Accepted Solution

by:
clifABB earned 100 total points
ID: 1463089
Dim hFile As Integer
Dim sText As String

hFile = FreeFile
Open "am.txt" For Input As hFile
Do Until EOF(hFile)
  Line Input hFile, sText
  Printer.Print sText
Loop
Printer.EndDoc
0
 

Author Comment

by:FaffMan
ID: 1463090
Nice one!

I'd actually got it working already, but my code took ages to print. Your code produces results a lot faster.

Dan


0
 
LVL 6

Expert Comment

by:clifABB
ID: 1463091
Glad I could be of help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question