Printer margins, printable area width

J

John Floyd

I have reports setup in an access 2000 DB. The printer
that I designed these reports around will handle a 0.5"
margin on top, bottom,left, and right sides. The other
printer I use will not support 0.5" on all sides. It will
default the right margin to 0.55". This causes the layout
of the report to over run the page and print a sigle grid
line, spreadsheet type report layout, on another page.
I have the report setup so that I can adjust the column
widths during formating of the reports, but I cannot
figure out how to get the printer magin settings (to
determine printable area) from my printer durring
formating of the report. I have found how to get the
paper size from the printer using the prtdevmode but this
does not help withthe changing margins. Is there a
command that will return the margins for the default
printer running my Dbase.
Thanks for any help that you can provide.
 
S

Steve Schapel

John,

This is a perennial problem. There may be a way to do what you ask, I
don't know. But I usually simply design all my reports such that they
are shorter and narrower than would be allowed by the clunkiest printer
they are ever likely to encounter.
 
S

SA

John:

To get the printer's printable area, you have to use some api calls, which
are somewhat extensive to do. Here's the code if you need it, but Steve
Schapel's recommendation to go with the minimum likely is much more prudent
in the long run.

HTH
--
Steve Arbaugh
ACG Soft
http://ourworld.compuserve.com/homepages/attac-cg

-------Declares----------
Private Declare Function CreateIC Lib "gdi32" Alias "CreateICA" (ByVal
lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As
String, ByVal lpInitData As Long) As Long
Private Declare Function DeleteDC32 Lib "gdi32" Alias "DeleteDC" (ByVal hDC
As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal
nIndex As Long) As Long

---------Functions---------
Public Function MakePDC(ByVal strPrinterDevice As String, Optional
lngDevMode As Long) As Long
Dim hDC As Long
hDC = CreateIC("WINSPOOL", strPrinterDevice, vbNullString, lngDevMode)
MakePDC = hDC
End Function

Public Function GetPrintableArea(ByVal strPrinterName As String, Optional
ByVal lngDevMode As Long = 0&)
Dim lngPhysicalWidth As Long
Dim lngPhysicalHeight As Long
Dim lngLeftOffSet As Long
Dim lngTopOffSet As Long
Dim lngRightOffset As Long
Dim lngBottomOffset As Long
Dim lngLogPX As Long
Dim lngLogPY As Long
Dim lngLeftMargin!, lngRightMargin!, lngTopMargin!, lngBottomMargin!
Dim dwReturn&
Dim hPDC As Long

Const PHYSICALWIDTH = 110 ' Physical Width in device units
Const PHYSICALHEIGHT = 111 ' Physical Height in device units
Const PHYSICALOFFSETX = 112 ' Physical Printable Area x margin
Const PHYSICALOFFSETY = 113 ' Physical Printable Area y margin
Const LOGPIXELSX = 88 ' Logical pixels/inch in X
Const LOGPIXELSY = 90 ' Logical pixels/inch in Y
Const HORZRES = 8 ' Horizontal width in pixels
Const VERTRES = 10 ' Vertical width in pixels


hPDC = MakePDC(strPrinterName, lngDevMode)
If hPDC = 0 Then Exit Function

lngLeftOffSet = GetDeviceCaps(hPDC, PHYSICALOFFSETX)
lngTopOffSet = GetDeviceCaps(hPDC, PHYSICALOFFSETY)
lngPhysicalWidth = GetDeviceCaps(hPDC, PHYSICALWIDTH)
lngPhysicalHeight = GetDeviceCaps(hPDC, PHYSICALHEIGHT)

lngLogPX = GetDeviceCaps(hPDC, LOGPIXELSX)
lngLogPY = GetDeviceCaps(hPDC, LOGPIXELSY)

lngRightOffset = lngPhysicalWidth - GetDeviceCaps(hPDC, HORZRES) -
lngLeftOffSet
lngBottomOffset = lngPhysicalHeight - GetDeviceCaps(hPDC, VERTRES) -
lngTopOffSet

lngTopMargin = lngTopOffSet / lngLogPY
lngBottomMargin = lngBottomOffset / lngLogPY
lngLeftMargin = lngLeftOffSet / lngLogPX
lngRightMargin = lngRightOffset / lngLogPX

Debug.Print "Min Top Margin Inches " & lngTopMargin & "; Twips: " &
lngTopMargin * 1440
Debug.Print "Min Bottom Margin Inches " & lngBottomMargin & "; Twips " &
lngBottomMargin * 1440
Debug.Print "Min Left Margin Inches " & lngLeftMargin & "; Twips: " &
lngLeftMargin * 1440
Debug.Print "Min Right Margin Inches " & lngRightMargin & "; Twips: " &
lngRightMargin * 1440
Debug.Print "Min Top Margin MM " & DblRound((lngTopMargin * 1440 / 566.9) *
10, 2)
Debug.Print "Min Bottom Margin MM " & DblRound((lngBottomMargin * 1440 /
566.9) * 10, 2)
Debug.Print "Min Left Margin MM " & DblRound((lngLeftMargin * 1440 / 566.9)
* 10, 2)
Debug.Print "Min Right Margin MM " & DblRound((lngRightMargin * 1440 /
566.9) * 10, 2)

dwReturn = DeleteDC32(hPDC)

End Function
 
S

SA

Oops, forgot the DblRound function:
--
Steve Arbaugh
ACG Soft
http://ourworld.compuserve.com/homepages/attac-cg

Public Function DblRound(ByVal Number As Variant, NumDigits As Long,
Optional UseBankersRounding As Boolean = False) As Double
Dim dblPower As Double
Dim varTemp As Variant
Dim intSgn As Integer

If Not IsNumeric(Number) Then
' Raise an error indicating that
' you've supplied an invalid parameter.
Err.Raise 5
End If
dblPower = 10 ^ NumDigits
' Is this a negative number, or not?
' intSgn will contain -1, 0, or 1.
intSgn = Sgn(Number)
Number = Abs(Number)

' Do the major calculation.
varTemp = CDec(Number) * dblPower + 0.5

' Now round to nearest even, if necessary.
If UseBankersRounding Then
If Int(varTemp) = varTemp Then
' You could also use:
' varTemp = varTemp + (varTemp Mod 2 = 1)
' instead of the next If ...Then statement,
' but I hate counting on TRue == -1 in code.
If varTemp Mod 2 = 1 Then
varTemp = varTemp - 1
End If
End If
End If
' Finish the calculation.
DblRound = intSgn * Int(varTemp) / dblPower
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top