[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

Print.Copies / Default Print Problem

I found this code on the Internet and I got everything to work but when I goto Print it will print to the default printer only and only do one copy, i cant find out where in the code to setup for multi copies and to tell it what printer to goto? Here is parts of the code.
0
thaburner
Asked:
thaburner
  • 4
1 Solution
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>I found this code on the Internet
Define 'this code', preferably by copy-pasting it into the question.
0
 
thaburnerAuthor Commented:

Global Const SRCCOPY = &HCC0020
Global Const BI_RGB = 0
Global Const DIB_RGB_COLORS = 0
Global Const GMEM_MOVEABLE = 2

' Module level variables set in PrintStartDoc flag indicating Printing
' or Previewing:
Global PrinterFlag
' Object used for Print Preview:
Global ObjPrint As Control
' Storage for output objects original scale mode:
Global sm
' The size ratio between the actual page and the print preview object:
Global Ratio
' Size of the non-printable area on printer:
Global LRGap
Global TBGap
' The actual paper size (8.5 x 11 normally):
Global PgWidth
Global PgHeight

Sub PrintStartDoc(objToPrintOn As Control, PF, PaperWidth, PaperHeight)
   Dim psm
   Dim fsm
   Dim HeightRatio
   Dim WidthRatio

   ' Set the flag that determines whether printing or previewing:
   PrinterFlag = PF

   ' Set the physical page size:
   PgWidth = PaperWidth
   PgHeight = PaperHeight

   ' Find the size of the non-printable area on the printer to
   ' use to offset coordinates. These formulas assume the
   ' non-printable area is centered on the page:
   psm = Printer.ScaleMode
   Printer.ScaleMode = 5 'Inches
   LRGap = (PgWidth - Printer.ScaleWidth) / 2
   TBGap = (PgHeight - Printer.ScaleHeight) / 2
   Printer.ScaleMode = psm
   
   ' Initialize printer or preview object:
   If PrinterFlag Then
      sm = Printer.ScaleMode
      Printer.ScaleMode = 5 'Inches
      Printer.Print "";
   Else
      ' Set the object used for preview:
      Set ObjPrint = objToPrintOn
      ' Scale Object to Printer's printable area in Inches:
      sm = ObjPrint.ScaleMode
      ObjPrint.ScaleMode = 5 'Inches
      ' Compare the height and with ratios to determine the
      ' Ratio to use and how to size the picture box:
      HeightRatio = ObjPrint.ScaleHeight / PgHeight
      WidthRatio = ObjPrint.ScaleWidth / PgWidth
      If HeightRatio < WidthRatio Then
         Ratio = HeightRatio
         ' Re-size picture box - this does not work on a form:
         fsm = ObjPrint.Parent.ScaleMode
         ObjPrint.Parent.ScaleMode = 5 'Inches
         ObjPrint.Width = PgWidth * Ratio
         ObjPrint.Parent.ScaleMode = fsm
      Else
         Ratio = WidthRatio
         ' Re-size picture box - this does not work on a form:
         fsm = ObjPrint.Parent.ScaleMode
         ObjPrint.Parent.ScaleMode = 5 'Inches
         ObjPrint.Height = PgHeight * Ratio
         ObjPrint.Parent.ScaleMode = fsm
      End If
      ' Set default properties of picture box to match printer
      ' There are many that you could add here:
      ObjPrint.Scale (0, 0)-(PgWidth, PgHeight)
      ObjPrint.FontName = Printer.FontName
      ObjPrint.FontSize = Printer.FontSize * Ratio
      ObjPrint.ForeColor = Printer.ForeColor
      ObjPrint.Cls
   End If
End Sub

Sub PrintPrint(PrintVar)
'On Error Resume Next
   If PrinterFlag Then
      Printer.Print PrintVar
   Else
      ObjPrint.Print PrintVar
   End If
End Sub

Sub PrintNewPage()
   If PrinterFlag Then
      Printer.NewPage
   Else
      ObjPrint.Cls
   End If
End Sub

' Enter the following two lines as one, single line:
Sub PrintPicture(picSource As Control, ByVal pLeft, ByVal pTop, _
   ByVal pWidth, ByVal pHeight)

   ' Picture Box should have autoredraw = False, ScaleMode = Pixel
   ' Also can have visible=false, Autosize = true

   Dim BitmapInfo As BITMAPINFO_TYPE
   Dim DesthDC As Long
   Dim hMem As Long
   Dim lpBits As Long
   Dim r As Long

   ' Precaution:
   If pLeft < LRGap Or pTop < TBGap Then Exit Sub
   If pWidth < 0 Or pHeight < 0 Then Exit Sub
   If pWidth + pLeft > PgWidth - LRGap Then Exit Sub
   If pHeight + pTop > PgHeight - TBGap Then Exit Sub
   picSource.ScaleMode = 3 'Pixels
   picSource.AutoRedraw = False
   picSource.Visible = False
   picSource.AutoSize = True

   If PrinterFlag Then
      Printer.ScaleMode = 3 'Pixels
      ' Calculate size in pixels:
      pLeft = ((pLeft - LRGap) * 1440) / Printer.TwipsPerPixelX
      pTop = ((pTop - TBGap) * 1440) / Printer.TwipsPerPixelY
      pWidth = (pWidth * 1440) / Printer.TwipsPerPixelX
      pHeight = (pHeight * 1440) / Printer.TwipsPerPixelY
      Printer.Print "";
      DesthDC = Printer.hDC
   Else
      ObjPrint.Scale
      ObjPrint.ScaleMode = 3 'Pixels
      ' Calculate size in pixels:
      pLeft = ((pLeft * 1440) / Screen.TwipsPerPixelX) * Ratio
      pTop = ((pTop * 1440) / Screen.TwipsPerPixelY) * Ratio
      pWidth = ((pWidth * 1440) / Screen.TwipsPerPixelX) * Ratio
      pHeight = ((pHeight * 1440) / Screen.TwipsPerPixelY) * Ratio
      DesthDC = ObjPrint.hDC
   End If

   BitmapInfo.BitmapInfoHeader.biSize = 40
   BitmapInfo.BitmapInfoHeader.biWidth = picSource.ScaleWidth
   BitmapInfo.BitmapInfoHeader.biHeight = picSource.ScaleHeight
   BitmapInfo.BitmapInfoHeader.biPlanes = 1
   BitmapInfo.BitmapInfoHeader.biBitCount = 8
   BitmapInfo.BitmapInfoHeader.biCompression = BI_RGB

   ' Enter the following two lines as one, single line:
   hMem = GlobalAlloc(GMEM_MOVEABLE, (CLng(picSource.ScaleWidth + 3) \ 4) * 4 * picSource.ScaleHeight) 'DWORD ALIGNED
   lpBits = GlobalLock(hMem)

   ' Enter the following two lines as one, single line:
   r = GetDIBits(picSource.hDC, picSource.Image, 0, picSource.ScaleHeight, lpBits, BitmapInfo, DIB_RGB_COLORS)
   If r <> 0 Then
      ' Enter the following two lines as one, single line:
      r = StretchDIBits(DesthDC, pLeft, pTop, pWidth, pHeight, 0, 0, _
         picSource.ScaleWidth, picSource.ScaleHeight, lpBits, _
         BitmapInfo, DIB_RGB_COLORS, SRCCOPY)
   End If

   r = GlobalUnlock(hMem)
   r = GlobalFree(hMem)

   If PrinterFlag Then
      Printer.ScaleMode = 5 'Inches
   Else
      ObjPrint.ScaleMode = 5 'Inches
      ObjPrint.Scale (0, 0)-(PgWidth, PgHeight)
   End If
End Sub

Sub PrintEndDoc()
   If PrinterFlag Then
      Printer.EndDoc
      Printer.ScaleMode = sm
   Else
      ObjPrint.ScaleMode = sm
   End If
End Sub
0
 
thaburnerAuthor Commented:
lol didnt give me enough time to paste it
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
ptan218Commented:
Maybe you can modify the code. Change the following function from

Sub PrintStartDoc(objToPrintOn As Control, PF, PaperWidth, PaperHeight)

to

Sub PrintStartDoc(objToPrintOn As Control, PF, PaperWidth, PaperHeight, Copies)

Then

Add the following code at the beginning of the section:

Sub PrintStartDoc(objToPrintOn As Control, PF, PaperWidth, PaperHeight)
   Dim psm
   Dim fsm
   Dim HeightRatio
   Dim WidthRatio

   ' Set the flag that determines whether printing or previewing:
   PrinterFlag = PF

   ' Set the physical page size:
   PgWidth = PaperWidth
   PgHeight = PaperHeight
   Printer.Copies = Copies              <---------------------------- ADD HERE
   ' Find the size of the non-printable area on the printer to
   ' use to offset coordinates. These formulas assume the
   ' non-printable area is centered on the page:
   psm = Printer.ScaleMode




0
 
thaburnerAuthor Commented:
that works great only other question i have it where does it print to the default printer, i need to have the user be able to select which printer for it to be directed to.
0
 
thaburnerAuthor Commented:
nm i figured it out have to do printer.devicename thanks alot for the help ptan
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now