FOR MCRIDER

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
chazterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mcriderCommented:
This is in reference to http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10263751 
 
What error message are you getting?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chazterAuthor Commented:
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
mcriderCommented:
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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

chazterAuthor Commented:
The box says:

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




Chazter
0
chazterAuthor Commented:
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
mcriderCommented:
Then your printer doesn't support orientation changing... Sorry.


Cheers!
0
chazterAuthor Commented:
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
chazterAuthor Commented:
Adjusted points to 80
0
chazterAuthor Commented:
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
mcriderCommented:
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
chazterAuthor Commented:
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
mcriderCommented:
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
chazterAuthor Commented:
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
chazterAuthor Commented:
Adjusted points to 280
0
mcriderCommented:
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
chazterAuthor Commented:
Adjusted points to 300
0
chazterAuthor Commented:
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
mcriderCommented:
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
mcriderCommented:
In the above example, i eliminated the width stretching completely and only stretch the height...


Cheers!
0
chazterAuthor Commented:
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
mcriderCommented:
Yes, it should work there as well...


Cheers!
0
chazterAuthor Commented:
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
chazterAuthor Commented:
I have yet to try the printing on the fax so bare with me...

chazter
0
mcriderCommented:
Unless I drop dead, I'll be here ;-)


Cheers!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.