Save Paper Size in Access Runtime

tatat

New member
Local time
Today, 13:50
Joined
Feb 5, 2005
Messages
6
My Access 2003 DB has numbers of customed paper size reports (e.g. tickets and labels) printed by dot-matrix printer.
I can save the correct size in design view and run smooth in full version of Access 2003.
However, when I print these reports in runtime version, all size become "Letter".

I have tried to set the size using VBA code
printer.papersize=256 but I can't find the way to set the size!
I can only change the size to 41 predefined size, but no one is fit my needs.
Also, I have tried the "PrtDevMode", "PaperLength" and "PaperWidth" to set the size in design view and works in full version. Unfortuatly, design view is not allowed in runtime.

I have to distribute the DB to other workstations, I can't affort the extra cost to purchase the Full verison of ACCE$$ 2003.

Any Expert can help me!!!!
 
How about this:

In the development app, create an export function for the report to a Snapshot format. Upgrade the runtime app to include the new function. Install the runtime on the remote computer, along with the Snapshot executable file.

I"m not sure it will work, just seeing if the Snapshot file will allow you to set the report size independently of the runtime app.
 
I would not recommend exporting to snapshot. If you are using a dot-matrix printer there is really no need for a fancy report. I would recommend outputting it to a txt file. This way you can control the output size by character string length. Dot-matrix printers are great for this and it will give you the most consistent results.

Access uses the settings of the of the default printer. You can change the setting of the default printer and settings programmatically but you have to remember to change it back. I wouldn't recommend this because drawn out and every PC is slightly different.
 
Thx for Help !

1) The snapshot in runtime still become "Letter" size. :confused:

2) The report contains barcode and sign icons, can't use text format.

I just code this program in a month but struggling in this simple paper size problem for an other month.

Is it a limitation in ACCESS ?? :mad:
 
Thx! dt01pqt

The ActiveX Barcode has no problem.

As you suggested output to text file to fix the paper size problem, it is difficult to control the barcode printing dimensions in a text format.
 
I have a funny founding that when I try to connect a network printer from client PC to my development PC and set it as default. All papersize setting appears in the reports even the printer is not the dot-matrix one. If I change the default to local printer, the paper size gone!

I guess the papersize setting is saved in the .mde including the selected print server name or the computer name that configure the printer setting.

Is there any way to find the print server value or make change on it?

TATAT
 
I have knocked some code together which may work in the runtime version. I have modified the code from A Code A day for the basic structure and added a default printer function from Albert D.Kallal. Note this just a basic function to show you how you could go about it not a complete code to enable you to change the settings back easily. Place in module:
Code:
Option Compare Database
Option Explicit

'@~~~~~~~ NT Security Constants ~~~~~~~~@
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const PRINTER_ACCESS_ADMINISTER = &H4
Private Const PRINTER_ACCESS_USE = &H8
Private Const PRINTER_ALL_ACCESS = _
(STANDARD_RIGHTS_REQUIRED Or PRINTER_ACCESS_ADMINISTER _
Or PRINTER_ACCESS_USE)

'@~~~~~~~ DEVMODE Constants ~~~~~~~~@
Private Const DM_MODIFY = 8
Private Const DM_IN_BUFFER = DM_MODIFY
Private Const DM_COPY = 2
Private Const DM_OUT_BUFFER = DM_COPY
Private Const DM_FORMNAME As Long = &H10000
Private Const DM_ORIENTATION = &H1&
Private Const DM_PAPERSIZE = &H2
Private Const DM_PAPERLENGTH = &H4
Private Const DM_PAPERWIDTH = &H8
Private Const DMORIENT_LANDSCAPE = 2
Private Const DMORIENT_PORTRAIT = 1

'@~~~~~~~~~~~ DEVMODE ~~~~~~~~~~~@
' I have removed all of the NT only and
' Windows 9X (2000 as well) only elements

Private Type DEVMODE
dmDeviceName As String * 32
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * 32
dmLogPixels As Integer
dmBitsPerPel As Long
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type

Type str_DEVMODE
    RGB As String * 94
End Type

Private Type PRINTER_DEFAULTS
pDatatype As String
pDevMode As Long
DesiredAccess As Long
End Type

Private Declare Function OpenPrinter Lib _
"winspool.drv" Alias "OpenPrinterA" _
(ByVal pPrinterName As String, phPrinter As Long, _
pDefault As PRINTER_DEFAULTS) As Long

Private Declare Function SetPrinter Lib _
"winspool.drv" Alias "SetPrinterA" _
(ByVal hPrinter As Long, ByVal Level As Long, _
pPrinter As Any, ByVal Command As Long) As Long

Private Declare Function GetPrinter Lib _
"winspool.drv" Alias "GetPrinterA" _
(ByVal hPrinter As Long, ByVal Level As Long, _
pPrinter As Any, ByVal cbBuf As Long, _
pcbNeeded As Long) As Long

Private Declare Function GetProfileString Lib "kernel32" _
   Alias "GetProfileStringA" _
  (ByVal lpAppName As String, _
   ByVal lpKeyName As String, _
   ByVal lpDefault As String, _
   ByVal lpReturnedString As String, _
   ByVal nSize As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" (hpvDest As Any, _
hpvSource As Any, ByVal cbCopy As Long)
Private Declare Function ClosePrinter Lib _
"winspool.drv" (ByVal hPrinter As Long) As Long

Private Declare Function DocumentProperties Lib _
"winspool.drv" Alias "DocumentPropertiesA" _
(ByVal hwnd As Long, ByVal hPrinter As Long, _
ByVal pDeviceName As String, ByVal _
pDevModeOutput As Any, ByVal pDevModeInput As Any, _
ByVal fMode As Long) As Long

Public Function SetPaperSizeOrientation(intPaperSize As Integer, _
                            intPaperWidth As Integer, intPaperLength As Integer, _
                            intOrientation As Integer)
Dim udtPD As PRINTER_DEFAULTS
Dim DevString As str_DEVMODE
Dim udtDEVMODE As DEVMODE
Dim strDevModeExtra As String
Dim lngBuffer() As Long
Dim lngPrnHndle As Long
Dim lngRetVal As Long
Dim lngDMpntr As Long
Dim lngRet As Long
Dim strPrintName As String

udtPD.pDatatype = vbNullString
udtPD.pDevMode = 0&
'The next call is NT security, it
'Has no adverse affect on Windows 9X or 2000
udtPD.DesiredAccess = PRINTER_ALL_ACCESS
strPrintName = GetDefaultPrinter
lngRet = OpenPrinter(strPrintName, lngPrnHndle, udtPD)
lngRet = GetPrinter(lngPrnHndle, 2, ByVal 0&, 0, lngRetVal)
ReDim lngBuffer((lngRetVal \ 4))
lngRet = GetPrinter(lngPrnHndle, 2, lngBuffer(0), _
lngRetVal, lngRetVal)

'The pointer (7th element of the array) to the DEVMODE
lngDMpntr = lngBuffer(7)
'Public to Private and vice-versa
Call CopyMemory(udtDEVMODE, ByVal lngDMpntr, Len(udtDEVMODE))
'Mark the bit and Change the orientation
udtDEVMODE.dmFields = udtDEVMODE.dmFields Or _
                    DM_ORIENTATION Or DM_PAPERSIZE _
                    Or DM_PAPERLENGTH Or DM_PAPERWIDTH _
                    And Not DM_FORMNAME
udtDEVMODE.dmOrientation = intOrientation
udtDEVMODE.dmPaperSize = intPaperSize
udtDEVMODE.dmPaperLength = intPaperLength
udtDEVMODE.dmPaperWidth = intPaperWidth

Call CopyMemory(ByVal lngDMpntr, udtDEVMODE, Len(udtDEVMODE))

lngRet = DocumentProperties(Access.Application.hWndAccessApp, _
lngPrnHndle, strPrintName, ByVal lngDMpntr, _
ByVal lngDMpntr, DM_IN_BUFFER Or DM_OUT_BUFFER)

'The Magic happens right here!
lngRet = SetPrinter(lngPrnHndle, 2, lngBuffer(0), 0&)
'All done
Call ClosePrinter(lngPrnHndle)
End Function

Private Function GetDefaultPrinter() As String
   Dim strDefault    As String
   Dim lngbuf        As Long
   strDefault = String(255, Chr(0))
   lngbuf = GetProfileString("Windows", "Device", "", strDefault, Len(strDefault))
   If lngbuf > 0 Then
      GetDefaultPrinter = fstrDField(strDefault, ",", 1)
   Else
      GetDefaultPrinter = ""
   End If
End Function

Private Function fstrDField(mytext As String, delim As String, groupnum As Integer) As String
   ' this is a standard delimiter routine that every developer I know has.
   ' This routine has a million uses. This routine is great for splitting up
   ' data fields, or sending multiple parms to a openargs of a form
   '
   '  Parms are
   '        mytext   - a delimited string
   '        delim    - our delimiter (usually a , or / or a space)
   '        groupnum - which of the delimited values to return
   '
Dim startpos As Integer, endpos As Integer
Dim groupptr As Integer, chptr As Integer
chptr = 1
startpos = 0
 For groupptr = 1 To groupnum - 1
    chptr = InStr(chptr, mytext, delim)
    If chptr = 0 Then
       fstrDField = ""
       Exit Function
    Else
       chptr = chptr + 1
    End If
 Next groupptr
startpos = chptr
endpos = InStr(startpos + 1, mytext, delim)
If endpos = 0 Then
   endpos = Len(mytext) + 1
End If
fstrDField = Mid$(mytext, startpos, endpos - startpos)
End Function
Example of how you could use it on the report:
Code:
Option Compare Database
Option Explicit

'Orientation
Const ORIENT_PORTRAIT = 1
Const ORIENT_LANDSCAPE = 2

'Paper Sizes
Private Const DMPAPER_USER_DEFINED = 256


Private Sub Report_Open(Cancel As Integer)
SetPaperSizeOrientation DMPAPER_USER_DEFINED, [I]width[/I], [I]length[/I], ORIENT_PORTRAIT
End Sub

Hope this helps
 
Here is the complete paper size constants:
Code:
'Paper Sizes
Private Const DMPAPER_LETTER = 1                 '  Letter 8 1/2 x 11 in
Private Const DMPAPER_LETTERSMALL = 2            '  Letter Small 8 1/2 x 11 in
Private Const DMPAPER_TABLOID = 3                '  Tabloid 11 x 17 in
Private Const DMPAPER_LEDGER = 4                 '  Ledger 17 x 11 in
Private Const DMPAPER_LEGAL = 5                  '  Legal 8 1/2 x 14 in
Private Const DMPAPER_STATEMENT = 6              '  Statement 5 1/2 x 8 1/2 in
Private Const DMPAPER_EXECUTIVE = 7              '  Executive 7 1/4 x 10 1/2 in
Private Const DMPAPER_A3 = 8                     '  A3 297 x 420 mm
Private Const DMPAPER_A4 = 9                     '  A4 210 x 297 mm
Private Const DMPAPER_A4SMALL = 10               '  A4 Small 210 x 297 mm
Private Const DMPAPER_A5 = 11                    '  A5 148 x 210 mm
Private Const DMPAPER_B4 = 12                    '  B4 250 x 354
Private Const DMPAPER_B5 = 13                    '  B5 182 x 257 mm
Private Const DMPAPER_FOLIO = 14                 '  Folio 8 1/2 x 13 in
Private Const DMPAPER_QUARTO = 15                '  Quarto 215 x 275 mm
Private Const DMPAPER_10X14 = 16                 '  10x14 in
Private Const DMPAPER_11X17 = 17                 '  11x17 in
Private Const DMPAPER_NOTE = 18                  '  Note 8 1/2 x 11 in
Private Const DMPAPER_ENV_9 = 19                 '  Envelope #9 3 7/8 x 8 7/8
Private Const DMPAPER_ENV_10 = 20                '  Envelope #10 4 1/8 x 9 1/2
Private Const DMPAPER_ENV_11 = 21                '  Envelope #11 4 1/2 x 10 3/8
Private Const DMPAPER_ENV_12 = 22                '  Envelope #12 4 \276 x 11
Private Const DMPAPER_ENV_14 = 23                '  Envelope #14 5 x 11 1/2
Private Const DMPAPER_CSHEET = 24                '  C size sheet
Private Const DMPAPER_DSHEET = 25                '  D size sheet
Private Const DMPAPER_ESHEET = 26                '  E size sheet
Private Const DMPAPER_ENV_DL = 27                '  Envelope DL 110 x 220mm
Private Const DMPAPER_ENV_C5 = 28                '  Envelope C5 162 x 229 mm
Private Const DMPAPER_ENV_C3 = 29                '  Envelope C3  324 x 458 mm
Private Const DMPAPER_ENV_C4 = 30                '  Envelope C4  229 x 324 mm
Private Const DMPAPER_ENV_C6 = 31                '  Envelope C6  114 x 162 mm
Private Const DMPAPER_ENV_C65 = 32               '  Envelope C65 114 x 229 mm
Private Const DMPAPER_ENV_B4 = 33                '  Envelope B4  250 x 353 mm
Private Const DMPAPER_ENV_B5 = 34                '  Envelope B5  176 x 250 mm
Private Const DMPAPER_ENV_B6 = 35                '  Envelope B6  176 x 125 mm
Private Const DMPAPER_ENV_ITALY = 36             '  Envelope 110 x 230 mm
Private Const DMPAPER_ENV_MONARCH = 37           '  Envelope Monarch 3.875 x 7.5 in
Private Const DMPAPER_ENV_PERSONAL = 38          '  6 3/4 Envelope 3 5/8 x 6 1/2 in
Private Const DMPAPER_FANFOLD_US = 39            '  US Std Fanfold 14 7/8 x 11 in
Private Const DMPAPER_FANFOLD_STD_GERMAN = 40    '  German Std Fanfold 8 1/2 x 12 in
Private Const DMPAPER_FANFOLD_LGL_GERMAN = 41    '  German Legal Fanfold 8 1/2 x 13 in
Private Const DMPAPER_USER_DEFINED = 256
 
?

Did anything work? I have similar problem..
The code example above crashed when I tried..

please advise
 
Temporary, I'm using a very stupid method to fix this problem :o

In my office, every workstation is connected to its dot-matrix printer, I share them all (there are 13 workstations only). Then, connect all printers from my dev. workstation.
After that, I make the mde 13 times, everytime I have to set the target workatation printer as default printer.
When I run the mde in the workstation with the same printer, all paper setting appears correctly.

I am sure that the mde remember the selected default print server name (Not the printer name). Therefore, the mde will work in a WS that connected to the same printer server as it is making.

I am plan to connect all printers to a single printer server to reduce the time to make mde.

Actually, I just want to put two values into the report - width and length. I don't know why I have to spend such a long time to find a simply solution. :(
 

Users who are viewing this thread

Back
Top Bottom