Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms access MS Access:自定义纸张大小_Ms Access_Vba_Printing_Page Size - Fatal编程技术网

Ms access MS Access:自定义纸张大小

Ms access MS Access:自定义纸张大小,ms-access,vba,printing,page-size,Ms Access,Vba,Printing,Page Size,我正在构建一个MS Access(2010)应用程序,并将从此应用程序打印条形码标签。也将使用标准打印机设置打印各种其他报告和表格,但是使用条形码,我需要将其打印到特定打印机,并且必须将其设置为使用特殊的页面大小 在我的搜索中,我有“Papersize”,它本身有很多“标准”默认选项,包括8.5“x 11”的标准美国字母的acPRPSLetter和A4纸张大小的acPRPSA4。所有预设尺寸都不适合我使用。有一个表示用户自定义大小的预设,acPRPSUser,但我没有找到任何方法以编程方式设置自

我正在构建一个MS Access(2010)应用程序,并将从此应用程序打印条形码标签。也将使用标准打印机设置打印各种其他报告和表格,但是使用条形码,我需要将其打印到特定打印机,并且必须将其设置为使用特殊的页面大小

在我的搜索中,我有“Papersize”,它本身有很多“标准”默认选项,包括8.5“x 11”的标准美国字母的acPRPSLetter和A4纸张大小的acPRPSA4。所有预设尺寸都不适合我使用。有一个表示用户自定义大小的预设,acPRPSUser,但我没有找到任何方法以编程方式设置自定义大小

我确实读过关于打印机的“.height”和“.width”属性是如何存在的,但在用于Access 2010的VB中似乎不存在这些属性(我相信它是基于VB6的)


有人能帮我在Access 2010中使用VB代码设置自定义纸张尺寸吗?

不需要VBA。您可以使用菜单中的页面设置命令设置页边距、方向、纸张、打印机和列的所有页面设置:报表设计工具>页面设置>页面设置>页面>纸张>大小,或>页面>打印机>使用特定打印机>打印机>属性。这些设置将为每个行业个别报告保存


看起来您需要查看
.DefaultSize
-如果这是真的,那么您的
itemsizewhight
ItemSizeWidth
设置将被忽略


有更多的信息和一些例子

我也有同样的问题。我用计算机解决了这个问题

我制作了一个带有程序打印输出的模块。通过函数Printerselection,我可以使用printername的特定部分调用打印机。PaperSelection函数用于使用纸张名称的特定部分指定纸张

首先,我必须使用DeviceCapabilities函数API调用的声明

    ' Declaration for the DeviceCapabilities function API call.
Private Declare Function DeviceCapabilities Lib "winspool.drv" _
    Alias "DeviceCapabilitiesA" (ByVal lpsDeviceName As String, _
    ByVal lpPort As String, ByVal iIndex As Long, lpOutput As Any, _
    ByVal lpDevMode As Long) As Long

' DeviceCapabilities function constants.
Private Const DC_PAPERNAMES = 16
Private Const DC_PAPERS = 2
Private Const DC_BINNAMES = 12
Private Const DC_BINS = 6
Private Const DEFAULT_VALUES = 0

Private Type str_DEVMODE
    RGB As String * 94
End Type

Private Type type_DEVMODE
    strDeviceName As String * 32
    intSpecVersion As Integer
    intDriverVersion As Integer
    intSize As Integer
    intDriverExtra As Integer
    lngFields As Long
    intOrientation As Integer
    intPaperSize As Integer
    intPaperLength As Integer
    intPaperWidth As Integer
    intScale As Integer
    intCopies As Integer
    intDefaultSource As Integer
    intPrintQuality As Integer
    intColor As Integer
    intDuplex As Integer
    intResolution As Integer
    intTTOption As Integer
    intCollate As Integer
    strFormName As String * 32
    lngPad As Long
    lngBits As Long
    lngPW As Long
    lngPH As Long
    lngDFI As Long
    lngDFr As Long
End Type

Private Cnt As Integer, PrinterSelect As Integer

Public Sub PrintOut(ByVal rptName As String, Printer As String, Paper As String, BinName As String, Optional Landscape As Boolean, Optional WhereCond)
Dim rpt As Report
DoCmd.OpenReport rptName, acViewPreview, , WhereCond
Set rpt = Reports(rptName)
PrinterSelect = PrinterSelection(Printer)
rpt.Printer = Application.Printers(PrinterSelect)
rpt.Printer.PaperSize = PaperSelection(Paper, PrinterSelect)
If Landscape Then
    rpt.Printer.Orientation = acPRORLandscape
Else
    rpt.Printer.Orientation = acPRORPortrait
End If
rpt.Printer.PaperBin = BinSelection(BinName, PrinterSelect)
End Sub

Public Function PrinterSelection(Printer As String) As Integer
For Cnt = 0 To Application.Printers.Count - 1
    If InStr(1, Application.Printers(Cnt).DeviceName, Printer) > 0 Then
        PrinterSelection = Cnt
    End If
Next Cnt
End Function

Public Function PaperSelection(Paper As String, Printer As Integer) As Integer

    Dim lngPaperCount As Long
    Dim lngCounter As Long
    Dim hPrinter As Long
    Dim strDeviceName As String
    Dim strDevicePort As String
    Dim strPaperNamesList As String
    Dim strPaperName As String
    Dim intLength As Integer
    Dim strMsg As String
    Dim aintNumPaper() As Integer

    On Error GoTo GetPaperList_Err

    ' Get the name and port of the selected printer.
    strDeviceName = Application.Printers(Printer).DeviceName
    strDevicePort = Application.Printers(Printer).Port

    ' Get the count of paper names supported by the printer.
    lngPaperCount = DeviceCapabilities(lpsDeviceName:=strDeviceName, _
        lpPort:=strDevicePort, _
        iIndex:=DC_PAPERNAMES, _
        lpOutput:=ByVal vbNullString, _
        lpDevMode:=DEFAULT_VALUES)

    ' Re-dimension the array to the count of paper names.
    ReDim aintNumPaper(1 To lngPaperCount)

    ' Pad the variable to accept 64 bytes for each paper name.
    strPaperNamesList = String(64 * lngPaperCount, 0)

    ' Get the string buffer of all paper names supported by the printer.
    lngPaperCount = DeviceCapabilities(lpsDeviceName:=strDeviceName, _
        lpPort:=strDevicePort, _
        iIndex:=DC_PAPERNAMES, _
        lpOutput:=ByVal strPaperNamesList, _
        lpDevMode:=DEFAULT_VALUES)

    ' Get the array of all paper numbers supported by the printer.
    lngPaperCount = DeviceCapabilities(lpsDeviceName:=strDeviceName, _
        lpPort:=strDevicePort, _
        iIndex:=DC_PAPERS, _
        lpOutput:=aintNumPaper(1), _
        lpDevMode:=DEFAULT_VALUES)

    ' List the available paper names.
    For lngCounter = 1 To lngPaperCount

        ' Parse a paper name from the string buffer.
        strPaperName = Mid(String:=strPaperNamesList, Start:=64 * (lngCounter - 1) + 1, Length:=64)
        intLength = VBA.InStr(Start:=1, String1:=strPaperName, String2:=Chr(0)) - 1
        strPaperName = Left(String:=strPaperName, Length:=intLength)
        If InStr(1, strPaperName, Paper) > 0 Then
        ' Select the a paper number corresponding to the paper name.
            PaperSelection = aintNumPaper(lngCounter)
        End If
    Next lngCounter


GetPaperList_End:
    Exit Function

GetPaperList_Err:
    MsgBox Prompt:=err.Description, Buttons:=vbCritical & vbOKOnly, _
        Title:="Error Number " & err.Number & " Occurred"
    Resume GetPaperList_End

End Function

Public Function BinSelection(BIN As String, Printer As Integer) As Integer
' Uses the DeviceCapabilities API function to choose the desired paper bin supported by the    chosen printer

    Dim lngBinCount As Long
    Dim lngCounter As Long
    Dim hPrinter As Long
    Dim strDeviceName As String
    Dim strDevicePort As String
    Dim strBinNamesList As String
    Dim strBinName As String
    Dim intLength As Integer
    Dim strMsg As String
    Dim aintNumBin() As Integer

    On Error GoTo GetBinList_Err

    ' Get name and port of the default printer.
    strDeviceName = Application.Printers(Printer).DeviceName
    strDevicePort = Application.Printers(Printer).Port

    ' Get count of paper bin names supported by the printer.
    lngBinCount = DeviceCapabilities(lpsDeviceName:=strDeviceName, _
        lpPort:=strDevicePort, _
        iIndex:=DC_BINNAMES, _
        lpOutput:=ByVal vbNullString, _
        lpDevMode:=DEFAULT_VALUES)

    ' Re-dimension the array to count of paper bins.
    ReDim aintNumBin(1 To lngBinCount)

    ' Pad variable to accept 24 bytes for each bin name.
    strBinNamesList = String(Number:=24 * lngBinCount, Character:=0)

    ' Get string buffer of paper bin names supported by the printer.
    lngBinCount = DeviceCapabilities(lpsDeviceName:=strDeviceName, _
        lpPort:=strDevicePort, _
        iIndex:=DC_BINNAMES, _
        lpOutput:=ByVal strBinNamesList, _
        lpDevMode:=DEFAULT_VALUES)

    ' Get array of paper bin numbers supported by the printer.
    lngBinCount = DeviceCapabilities(lpsDeviceName:=strDeviceName, _
        lpPort:=strDevicePort, _
        iIndex:=DC_BINS, _
        lpOutput:=aintNumBin(1), _
        lpDevMode:=0)

    ' List available paper bin names.
    strMsg = "Paper bins available for " & strDeviceName & vbCrLf
    For lngCounter = 1 To lngBinCount

        ' Parse a paper bin name from string buffer.
        strBinName = Mid(String:=strBinNamesList, _
            Start:=24 * (lngCounter - 1) + 1, _
            Length:=24)
        intLength = VBA.InStr(Start:=1, _
            String1:=strBinName, String2:=Chr(0)) - 1
        strBinName = Left(String:=strBinName, _
                Length:=intLength)

        If InStr(1, strBinName, BIN) > 0 Then
        ' Select the bin number corresponding to the bin name.
            BinSelection = aintNumBin(lngCounter)
        End If
     Next lngCounter


GetBinList_End:
    Exit Function
GetBinList_Err:
    MsgBox Prompt:=err.Description, Buttons:=vbCritical & vbOKOnly, _
        Title:="Error Number " & err.Number & " Occurred"
    Resume GetBinList_End
End Function

怎么样?我确实看到了,并且打算把它写在我的帖子里。谢谢你找到它。这显示了正在使用的“.papersize”属性,该属性在示例中使用的是如上所述的acPRPSLetter。这就是我所说的,因为没有更好的术语,一个预设。我需要使用自定义大小。列表的最后一个是acPRPSUser(),正如我在上面的问题中所指出的。我想知道的是如何准确地设置由acPRPSUser表示的自定义“用户”大小的纸张的大小。这与我想要的更接近,但不完全相同。此文件将在不同的计算机上使用,因此需要使用Access文件配置纸张大小设置,因为从支持的角度来看,在每台机器上分别手动配置打印机是不实际的。如果可能的话,我希望以编程的方式进行设置,这样运行此文件的每台计算机都会确切地知道如何处理标签。