?
Solved

FOR MCRIDER

Posted on 2000-01-27
24
Medium Priority
?
218 Views
Last Modified: 2010-05-02
Mc it hasn't worked mate, i know my printer can do it. When trying to print it come up with the error message


Chazter
0
Comment
Question by:chazter
  • 14
  • 10
24 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 1200 total points
ID: 2394617
This is in reference to http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10263751 
 
What error message are you getting?
0
 

Author Comment

by:chazter
ID: 2394941
Here's my code that i'm using to print to my local printer:-

On Error GoTo errorhandler
   Dim X As Printer
       For Each X In Printers
           If X.DeviceName = "EPSON Stylus COLOR 1520" Then
               Set Printer = X
               Exit For
           End If
       Next
       Printer.Orientation = vbPRORLandscape
       Printer.PaperSize = vbPRPSA5

       Form1.PrintForm
       Printer.EndDoc
   Exit Sub 'THIS LINE WAS MISSING IN YOUR CODE

errorhandler:
   MsgBox "There was an error sending the fax!", vbCritical, "Error!"

When i try and print it i get the error handling message.

Chris
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2395498
That code does not generate an error on my system... Change your errorhandler code to this:

errorhandler:
   MsgBox "There was an error sending the fax!" + vbCrLf _
    + CStr(Err) + " " + Error$(Err), vbCritical, "Error!"


Run the program again and let me know what the message box says...


Cheers!
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:chazter
ID: 2397550
The box says:

There was an error sending the fax!
486 can't print form image to this type of printer




Chazter
0
 

Author Comment

by:chazter
ID: 2397553
The box says:

There was an error sending the fax!
486 can't print form image to this type of printer

But it does work cause when the orientation isn't set it prints...odd.


Chazter
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2398330
Then your printer doesn't support orientation changing... Sorry.


Cheers!
0
 

Author Comment

by:chazter
ID: 2411941
It does mate, thats just it, the printer is very new, and i can do it with other things.

How would i make it bigger when sending it to the printer or the fax machine?

Chazter
0
 

Author Comment

by:chazter
ID: 2413141
Adjusted points to 80
0
 

Author Comment

by:chazter
ID: 2413142
I have inceased to points to 80 for ya.

I think i know what the problem is, i read on the Microsoft website site that you can't set printer orientations or sizes when using .printform.

So how do i get around this mate?

Chazter
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2424921
You could try this:

HOWTO: Capture and Print the Screen, a Form, or any Window
http://support.microsoft.com/support/kb/articles/q161/2/99.asp?LNG=ENG&SA=MSDN 
 

Cheers!

0
 

Author Comment

by:chazter
ID: 2444721
Mc this isn't really good mate, please can u help mate i'll add an extra 200 points if u can me help me out buddy.

Chazter
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2447121
Ok, try this:

1) Add a form to your project called "FormPrint".

2) Add a picturebox to the form "FormPrint" called "Picture1".

3) Add the following code to the GENERAL DECLARATIONS section of "FormPrint":

    '---------------------------------------------------------------------------
    Public Sub SendToPrinter(lObject As Object, lOrientation As pOrientType, _
        Optional lTop As Variant, Optional lLeft As Variant)
        Dim SaveOrientation As Long
        Dim lX As Single
        Dim lY As Single
        lX = IIf(IsMissing(lLeft), 0, CSng(lLeft))
        lY = IIf(IsMissing(lTop), 0, CSng(lTop))
       
        SaveOrientation = Printer.Orientation
        Printer.Orientation = lOrientation
        With Picture1
            .AutoRedraw = True
            Set .Picture = CaptureForm(lObject)
            Printer.PaintPicture .Picture, lX, lY
            Printer.EndDoc
        End With
        Printer.Orientation = SaveOrientation
        Unload FormPrint
    End Sub
    '---------------------------------------------------------------------------



4) Add a MODULE to your project.

5) Add the following code to the module:

    '---------------------------------------------------------------------------
    Option Explicit
    Option Base 0
    Private Const RASTERCAPS As Long = 38
    Private Const RC_PALETTE As Long = &H100
    Private Const SIZEPALETTE As Long = 104
   
    Public Enum pOrientType
        Portrait = 1
        Landscape = 2
    End Enum
   
    Private Type PALETTEENTRY
        peRed As Byte
        peGreen As Byte
        peBlue As Byte
        peFlags As Byte
    End Type
   
    Private Type LOGPALETTE
        palVersion As Integer
        palNumEntries As Integer
        palPalEntry(255) As PALETTEENTRY  ' Enough for 256 colors
    End Type
   
    Private Type GUID
        Data1 As Long
        Data2 As Integer
        Data3 As Integer
        Data4(7) As Byte
    End Type
   
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
   
    Private Type PicBmp
        Size As Long
        Type As Long
        hBmp As Long
        hPal As Long
        Reserved As Long
    End Type
   
    Private Declare Function CreateCompatibleDC _
        Lib "GDI32" (ByVal hDC As Long) As Long
       
    Private Declare Function CreateCompatibleBitmap _
        Lib "GDI32" (ByVal hDC As Long, ByVal nWidth As Long, _
        ByVal nHeight As Long) As Long
       
    Private Declare Function GetDeviceCaps _
        Lib "GDI32" (ByVal hDC As Long, ByVal iCapabilitiy As Long) As Long
       
    Private Declare Function GetSystemPaletteEntries _
        Lib "GDI32" (ByVal hDC As Long, ByVal wStartIndex As Long, _
        ByVal wNumEntries As Long, lpPaletteEntries As PALETTEENTRY) As Long
       
    Private Declare Function CreatePalette _
        Lib "GDI32" (lpLogPalette As LOGPALETTE) As Long
       
    Private Declare Function SelectObject _
        Lib "GDI32" (ByVal hDC As Long, ByVal hObject As Long) As Long
       
    Private Declare Function BitBlt _
        Lib "GDI32" (ByVal hDCDest As Long, ByVal XDest As Long, _
        ByVal YDest As Long, ByVal nWidth As Long, _
        ByVal nHeight As Long, ByVal hDCSrc As Long, _
        ByVal XSrc As Long, ByVal YSrc As Long, ByVal dwRop As Long) As Long
       
    Private Declare Function DeleteDC _
        Lib "GDI32" (ByVal hDC As Long) As Long
       
    Private Declare Function GetForegroundWindow _
        Lib "user32" () As Long
       
    Private Declare Function SelectPalette _
        Lib "GDI32" (ByVal hDC As Long, ByVal hPalette As Long, _
        ByVal bForceBackground As Long) As Long
       
    Private Declare Function RealizePalette _
        Lib "GDI32" (ByVal hDC As Long) As Long
       
    Private Declare Function GetWindowDC _
        Lib "user32" (ByVal hwnd As Long) As Long
       
    Private Declare Function GetDC _
        Lib "user32" (ByVal hwnd As Long) As Long
       
    Private Declare Function GetWindowRect _
        Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
       
    Private Declare Function ReleaseDC _
        Lib "user32" (ByVal hwnd As Long, ByVal hDC As Long) As Long
       
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
   
    Private Declare Function OleCreatePictureIndirect _
       Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, _
       ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
   
    Public Function CaptureWindow(ByVal hWndSrc As Long, _
        ByVal Client As Boolean, ByVal LeftSrc As Long, _
        ByVal TopSrc As Long, ByVal WidthSrc As Long, _
        ByVal HeightSrc As Long) As Picture
        Dim hDCMemory As Long
        Dim hBmp As Long
        Dim hBmpPrev As Long
        Dim r As Long
        Dim hDCSrc As Long
        Dim hPal As Long
        Dim hPalPrev As Long
        Dim RasterCapsScrn As Long
        Dim HasPaletteScrn As Long
        Dim PaletteSizeScrn As Long
        Dim LogPal As LOGPALETTE
   
        If Client Then
            hDCSrc = GetDC(hWndSrc)
        Else
            hDCSrc = GetWindowDC(hWndSrc)
        End If
        hDCMemory = CreateCompatibleDC(hDCSrc)
        hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc)
        hBmpPrev = SelectObject(hDCMemory, hBmp)
        RasterCapsScrn = GetDeviceCaps(hDCSrc, RASTERCAPS)
        HasPaletteScrn = RasterCapsScrn And RC_PALETTE
        PaletteSizeScrn = GetDeviceCaps(hDCSrc, SIZEPALETTE)
        If HasPaletteScrn And (PaletteSizeScrn = 256) Then
            LogPal.palVersion = &H300
            LogPal.palNumEntries = 256
            r = GetSystemPaletteEntries(hDCSrc, 0, 256, LogPal.palPalEntry(0))
            hPal = CreatePalette(LogPal)
            hPalPrev = SelectPalette(hDCMemory, hPal, 0)
            r = RealizePalette(hDCMemory)
        End If
        r = BitBlt(hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, _
            LeftSrc, TopSrc, vbSrcCopy)
        hBmp = SelectObject(hDCMemory, hBmpPrev)
        If HasPaletteScrn And (PaletteSizeScrn = 256) Then
            hPal = SelectPalette(hDCMemory, hPalPrev, 0)
        End If
        r = DeleteDC(hDCMemory)
        r = ReleaseDC(hWndSrc, hDCSrc)
        Set CaptureWindow = CreateBitmapPicture(hBmp, hPal)
    End Function
    Public Function CreateBitmapPicture(ByVal hBmp As Long, _
        ByVal hPal As Long) As Picture
        Dim r As Long
        Dim Pic As PicBmp
        Dim IPic As IPicture
        Dim IID_IDispatch As GUID
   
        With IID_IDispatch
            .Data1 = &H20400
            .Data4(0) = &HC0
            .Data4(7) = &H46
        End With
        With Pic
            .Size = Len(Pic)
            .Type = vbPicTypeBitmap
            .hBmp = hBmp
            .hPal = hPal
        End With
        r = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
        Set CreateBitmapPicture = IPic
    End Function
    Public Function CaptureForm(frmSrc As Form) As Picture
        Set CaptureForm = CaptureWindow(frmSrc.hwnd, False, 0, 0, _
            frmSrc.ScaleX(frmSrc.Width, vbTwips, vbPixels), _
            frmSrc.ScaleY(frmSrc.Height, vbTwips, vbPixels))
    End Function
    '---------------------------------------------------------------------------

   
6) Now to print Form1, you can do this:

   FormPrint.SendToPrinter Form1, Landscape



Hope this help!


Cheers!

Don't forget to increase the points... ;-)


0
 

Author Comment

by:chazter
ID: 2483077
Ok its printing the form to my printer but i need the form to size to A5. Also at the moment it also printing half of my START menu bar.

Chazter

p.s Your the most helpful person i have ever met, thanks :))
0
 

Author Comment

by:chazter
ID: 2483252
Adjusted points to 280
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2483764
I am assuming that you want to stretch the picture to fit on an A5... To do this, in the SendToPrinter subroutine above, change the line:

   Printer.PaintPicture .Picture, lX, lY

To:

   Printer.PaintPicture .Picture, lX, lY, Printer.ScaleWidth, Printer.ScaleHeight


Then before you call "FormPrint.SendToPrinter Form1, Landscape" to print the form, do this:

   Printer.PaperSize = vbPRPSA5


As for printing part of the start menu bar, that's bizzare! try moving your form up on the screen so that the start bar doesn't cover the form...


Hope this helps!


Cheers!
0
 

Author Comment

by:chazter
ID: 2483798
Adjusted points to 300
0
 

Author Comment

by:chazter
ID: 2483800
Mc mate it didn't work right, it stretched it the wrong way. It pulled the form to A5 but it pulled it on the width, so the form looks disorted.

Chaz
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2483844
The 4th & 5th arguments of the PaintPicture function deal with stretching the picture to fit the page... I think you'll have to play with it alittle bit...  Try this:

Printer.PaintPicture .Picture, lX, lY, , Printer.ScaleHeight


Cheers!
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2483845
In the above example, i eliminated the width stretching completely and only stretch the height...


Cheers!
0
 

Author Comment

by:chazter
ID: 2486987
Ok i got the printing right i used this line to fix it:

Printer.PaintPicture .Picture, lX, lY, Printer.ScaleWidth / 2, Printer.ScaleHeight

Thanks mate, will this send ik to the fax aswell?

Chazter
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2488155
Yes, it should work there as well...


Cheers!
0
 

Author Comment

by:chazter
ID: 2489906
Well mate you have been really helpful to me thanks and here is the 300 points i owe, if i get stuck on something else could you help me out again?

Thanks mate

Chazter
0
 

Author Comment

by:chazter
ID: 2489909
I have yet to try the printing on the fax so bare with me...

chazter
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2490050
Unless I drop dead, I'll be here ;-)


Cheers!
0

Featured Post

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.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

601 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