|
-
Feb 2nd, 2001, 08:28 PM
#1
Thread Starter
PowerPoster
Hiya
Anyone know how I can print the contents of a listbox line by line, nothing fancy, just plain text. I would like to have the Printer dialog come up as well if that is possible.
Thank you!
-
Feb 2nd, 2001, 08:42 PM
#2
Code:
Private Sub Command1_Click()
Dim iList As Integer
Dim sList As String
For iList = 0 to List1.ListCount - 1
sList = sList & List1.List(iList) & vbCrLf
Next iList
If Msgbox("Would you like to print?", vbOKCancel) = vbOK Then
Printer.Print sList
Printer.EndDoc
Else
Msgbox "Printing canceled."
End If
End Sub
-
Feb 2nd, 2001, 08:44 PM
#3
_______
<?>
Code:
Option Explicit
'
'API function to call the printer dialog box
'
Private Declare Function PrintDlg Lib "comdlg32.dll" _
Alias "PrintDlgA" (pPrintdlg As PRINTDLGS) As Long
Private Type PRINTDLGS
lStructSize As Long
hwndOwner As Long
hDevMode As Long
hDevNames As Long
hDC As Long
flags As Long
nFromPage As Integer
nToPage As Integer
nMinPage As Integer
nMaxPage As Integer
nCopies As Integer
hInstance As Long
lCustData As Long
lpfnPrintHook As Long
lpfnSetupHook As Long
lpPrintTemplateName As String
lpSetupTemplateName As String
hPrintTemplate As Long
hSetupTemplate As Long
End Type
Private Sub Command1_Click()
Dim PrintStruct As PRINTDLGS
PrintStruct.lStructSize = Len(PrintStruct)
Call PrintDlg(PrintStruct)
With List1
For i = 0 To .ListCount - 1
Printer.Print List1.List(i)
Next
End With
Printer.EndDoc 'start printer
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Feb 2nd, 2001, 09:02 PM
#4
Thread Starter
PowerPoster
Thanks guys! Swift response...however HeSaidJoe, it just prints to the default printer, no matter which printer you select in the dialog!
Last edited by chrisjk; Feb 2nd, 2001 at 09:09 PM.
-
Feb 3rd, 2001, 06:43 PM
#5
_______
<?>
Sorry, kicked out early and gone fishing all day.
Try changing your command1 code to this...actually just added one new line but I only have one printer so I can't test it.
Code:
Private Sub Command1_Click()
Dim PrintStruct As PRINTDLGS
PrintStruct.lStructSize = Len(PrintStruct)
Call PrintDlg(PrintStruct)
Set Printer = Printer.DeviceName
With List1
For i = 0 To .ListCount - 1
Printer.Print List1.List(i)
Next
End With
Printer.EndDoc 'start printer
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Feb 3rd, 2001, 09:25 PM
#6
Thread Starter
PowerPoster
Caught anything big? :)
Thanks ...Joe but I already tried that one and it either didn't make any difference, or just plan blew up...Object Required apparently.
Doh!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|