MaximoAccess

Caro Usuário, antes de postar pela primeira vez, leia as regras do fórum.

https://www.maximoaccess.com/t48-regras-do-forum

Obrigado

Administração


Participe do fórum, é rápido e fácil

MaximoAccess

Caro Usuário, antes de postar pela primeira vez, leia as regras do fórum.

https://www.maximoaccess.com/t48-regras-do-forum

Obrigado

Administração

MaximoAccess

Gostaria de reagir a esta mensagem? Crie uma conta em poucos cliques ou inicie sessão para continuar.

Dicas Ms Access, Exemplos Ms Access, Codigos VBA Ms Access, SQL Ms Access


2 participantes

    Abrir caixa de diálogo para impressão - MSAccess

    avatar
    Canassc
    Novato
    Novato


    Respeito às regras : Respeito às Regras 100%

    Sexo : Masculino
    Localização : Brasil
    Mensagens : 2
    Registrado : 21/09/2020

    Abrir caixa de diálogo para impressão - MSAccess Empty Abrir caixa de diálogo para impressão - MSAccess

    Mensagem  Canassc 22/2/2021, 20:22

    Boa tarde.
    Estou tentando criar um caminho para ao solicitar impressão, antes de imprimir abra a caixa de impressoras para poder selecionar um destino.
    Eu encontrei uma API para esta finalidade, porém não está funcionando e não estou conseguindo encontrar o erro.

    Código:
    Public Sub ShowPrinter(frmOwner As Form, Optional PrintFlags As Long)
       '-> Code by Donald Grover
       Dim PrintDlg As PRINTDLG_TYPE
       Dim DevMode As DEVMODE_TYPE
       Dim DevName As DEVNAMES_TYPE

       Dim lpDevMode As Long, lpDevName As Long
       Dim bReturn As Integer
       Dim objPrinter As Printer, NewPrinterName As String

       ' Use PrintDialog to get the handle to a memory
       ' block with a DevMode and DevName structures

       PrintDlg.lStructSize = Len(PrintDlg)
       PrintDlg.hwndOwner = frmOwner.hwnd

       PrintDlg.flags = PrintFlags
       On Error Resume Next
       'Set the current orientation and duplex setting
       DevMode.dmDeviceName = Printer.DeviceName
       DevMode.dmSize = Len(DevMode)
       DevMode.dmFields = DM_ORIENTATION Or DM_DUPLEX
       'DevMode.dmPaperWidth = Printer.Width
       DevMode.dmPaperWidth = Printer.ItemSizeWidth
       DevMode.dmOrientation = Printer.Orientation
       DevMode.dmPaperSize = Printer.PaperSize
       DevMode.dmDuplex = Printer.Duplex
       On Error GoTo 0

       'Allocate memory for the initialization hDevMode structure
       'and copy the settings gathered above into this memory
       PrintDlg.hDevMode = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, Len(DevMode))
       lpDevMode = GlobalLock(PrintDlg.hDevMode)
       If lpDevMode > 0 Then
           CopyMemory ByVal lpDevMode, DevMode, Len(DevMode)
           bReturn = GlobalUnlock(PrintDlg.hDevMode)
       End If

       'Set the current driver, device, and port name strings
       With DevName
           .wDriverOffset = 8
           .wDeviceOffset = .wDriverOffset + 1 + Len(Printer.DriverName)
           .wOutputOffset = .wDeviceOffset + 1 + Len(Printer.Port)
           .wDefault = 0
       End With

       With Printer
           DevName.extra = .DriverName & Chr(0) & .DeviceName & Chr(0) & .Port & Chr(0)
       End With

       'Allocate memory for the initial hDevName structure
       'and copy the settings gathered above into this memory
       PrintDlg.hDevNames = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, Len(DevName))
       lpDevName = GlobalLock(PrintDlg.hDevNames)
       If lpDevName > 0 Then
           CopyMemory ByVal lpDevName, DevName, Len(DevName)
           bReturn = GlobalUnlock(lpDevName)
       End If

       'Call the print dialog up and let the user make changes
       If PrintDialog(PrintDlg) <> 0 Then
           'First get the DevName structure.
           lpDevName = GlobalLock(PrintDlg.hDevNames)
           CopyMemory DevName, ByVal lpDevName, 45
           bReturn = GlobalUnlock(lpDevName)
           GlobalFree PrintDlg.hDevNames

           'Next get the DevMode structure and set the printer
           'properties appropriately
           lpDevMode = GlobalLock(PrintDlg.hDevMode)
           CopyMemory DevMode, ByVal lpDevMode, Len(DevMode)
           bReturn = GlobalUnlock(PrintDlg.hDevMode)
           GlobalFree PrintDlg.hDevMode
           'NewPrinterName = UCase$(Left(DevMode.dmDeviceName, InStr(DevMode.dmDeviceName, Chr$(0)) - 1))
           Dim A
           NewPrinterName = UCase$(Trim(DevMode.dmDeviceName))
           'NewPrinterName = UCase$(Left(DevMode.dmDeviceName, InStr(DevMode.dmDeviceName, Chr$(0)) - 1))
           If Printer.DeviceName <> NewPrinterName Then
               For Each objPrinter In Printers
                   If UCase$(objPrinter.DeviceName) = NewPrinterName Then
                       Set Printer = objPrinter
                       'set printer toolbar name at this point
                   End If
               Next
           End If

           On Error Resume Next
           'Set printer object properties according to selections made
           'by user
           Printer.Copies = DevMode.dmCopies
           Printer.Duplex = DevMode.dmDuplex
           Printer.Orientation = DevMode.dmOrientation
           Printer.PaperSize = DevMode.dmPaperSize
           Printer.PrintQuality = DevMode.dmPrintQuality
           Printer.ColorMode = DevMode.dmColor
           Printer.PaperBin = DevMode.dmDefaultSource
           On Error GoTo 0
       End If
    End Sub
    Anexos
    Abrir caixa de diálogo para impressão - MSAccess AttachmentAPI Impressao.txt
    Você não tem permissão para fazer download dos arquivos anexados.
    (18 Kb) Baixado 9 vez(es)
    Alvaro Teixeira
    Alvaro Teixeira
    Moderador Global
    Moderador Global


    Respeito às regras : Respeito às Regras 100%

    Sexo : Masculino
    Localização : Portugal
    Mensagens : 7919
    Registrado : 15/03/2013

    Abrir caixa de diálogo para impressão - MSAccess Empty Re: Abrir caixa de diálogo para impressão - MSAccess

    Mensagem  Alvaro Teixeira 22/2/2021, 20:31

    Olá Carlos Martins,

    Bem-Vindo ao fórum.

    Veja mensagem nº 13 do tópico abaixo:
    https://www.maximoaccess.com/t17902-resolvidoimprimir-relatorio-frente-e-verso

    Abraço

      Data/hora atual: 28/4/2024, 13:27