IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Access Discussion :

marge et nom imprimante


Sujet :

Access

  1. #1
    Nouveau membre du Club
    Inscrit en
    Mai 2004
    Messages
    60
    Détails du profil
    Informations forums :
    Inscription : Mai 2004
    Messages : 60
    Points : 38
    Points
    38
    Par défaut marge et nom imprimante
    Bonjour

    Je suis un informaticien expert en ACCESS mais comme on dit on est jamais expert à 100 %, chaque jour on apprend de nouvelles choses.

    J'ai développé une application qui permet de saisir toutes les informations nécessaires dans une table pour permetre d'éditer le chèque selon plusieurs modèle de banque sur l'imprimante reliée au port USB et d'éditer la letre d'accusé sur l'imprimante par défaut reliée au port parallele.

    Je spécifie l'imprimante USB dans l'etat du chèque (Fichier / Mise en page / Page )

    Le problème c'est que à chaque fois je change le nom de l'imprimante ou je la réinstalle, il y a un décalage des données imprimées sur le chèque.

    Est ce qu'il y a une possibilité de saisir les marges et le nom de l'imprimante via des zones de texte et les envoyer à l'imprimante pour ne pas avoir de décalage sur le chèque.

    Merci

  2. #2
    Membre régulier
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Octobre 2005
    Messages
    93
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Octobre 2005
    Messages : 93
    Points : 90
    Points
    90
    Par défaut Pistes à explorer


    Salut !

    Mon non plus je n'aime pas les mises en page aléatoires.
    Ce code à placer dans un module "Impression" par exemple te permettra d'inposer les marges.

    Il faut evidemment appeler la fonction "ModifierMarges" avant d'appeler l'état:

    Syntaxe:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    ' Modifier les marges d'un rapport avant de l'imprimer
    ' paramètres : 1- le nom du rapport en texte
    ' 2- la marge du haut en cm
    ' 3- la marge du bas en cm
    ' 4- la marge du gauche en cm
    ' 5- la marge du droite en cm
    ' exemple :
    ' ModifierMarges "Contacts", 1, 1, 1.5, 1.5
    ' DoCmd.OpenReport "Contacts", acViewPreview
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
     
    Option Compare Database
    Option Explicit
     
    '********************* Code Start **********************************
    'The code related to the Removal of Min/Max/Close button in reports*
    'was originally written by Terry Kreft & Keri Hardwick.            *
    '*******************************************************************
     
    Private Type RECT  '  16  Bytes
        left As Long
        top As Long
        right As Long
        bottom As Long
    End Type
     
    Private Declare Function apiGetWindowLong Lib "user32" _
        Alias "GetWindowLongA" _
        (ByVal hwnd As Long, _
        ByVal nIndex As Long) _
        As Long
     
    Private Declare Function apiSetWindowLong Lib "user32" _
        Alias "SetWindowLongA" _
        (ByVal hwnd As Long, _
        ByVal nIndex As Long, _
        ByVal dwNewLong As Long) _
        As Long
     
    Private Declare Function apiGetWindowRect Lib "user32" _
        Alias "GetWindowRect" _
        (ByVal hwnd As Long, _
        lpRect As RECT) _
        As Long
     
    Private Declare Function apiGetSystemMetrics Lib "user32" _
        Alias "GetSystemMetrics" _
        (ByVal nIndex&) _
        As Long
     
    Private Declare Function apiReleaseDC Lib "user32" _
      Alias "ReleaseDC" _
      (ByVal hwnd As Long, _
      ByVal hDC As Long) _
      As Long
     
    Private Declare Function apiGetDeviceCaps Lib "Gdi32" _
        Alias "GetDeviceCaps" _
        (ByVal hDC As Long, _
        ByVal nIndex As Long) _
        As Long
     
    Private Declare Function apiGetDC Lib "user32" _
        Alias "GetDC" _
        (ByVal hwnd As Long) _
        As Long
     
    Private Declare Function IsZoomed Lib "user32" _
        (ByVal hwnd As Long) As Long
     
    Private Declare Function ShowWindow Lib "user32" _
        (ByVal hwnd As Long, _
        ByVal nCmdShow As Long) As Long
     
    Private Declare Function MoveWindow Lib "user32" _
        (ByVal hwnd As Long, _
        ByVal x As Long, _
        ByVal Y As Long, _
        ByVal nWidth As Long, _
        ByVal nHeight As Long, _
        ByVal bRepaint As Long) As Long
     
    Private Declare Function GetParent Lib "user32" _
        (ByVal hwnd As Long) As Long
     
    'Use following instead of GetWindowRect
    Private Declare Function GetClientRect Lib "user32" _
        (ByVal hwnd As Long, _
        lpRect As RECT) As Long
     
    Public Const SW_MAXIMIZE = 3
    Public Const SW_SHOWNORMAL = 1
    Private Const GWL_EXSTYLE = -20
    Private Const GWL_HINSTANCE = -6
    Private Const GWL_HWNDPARENT = -8
    Private Const GWL_ID = -12
    Private Const GWL_STYLE = -16
    Private Const GWL_USERDATA = -21
    Private Const GWL_WNDPROC = -4
    Private Const WS_CAPTION = &HC00000
    Private Const WS_SYSMENU = &H80000
    Private Const SM_CYCAPTION = 4  ' Height of caption or title
    Private Const TWIPSPERINCH = 1440
    '**  Window Style Constants
    Private Const WS_DLGFRAME& = &H400000
    Private Const WS_THICKFRAME& = &H40000
     
    'Début de section pour les Types nécessaires à la fonction ModifierMarges
    Type ch_DEVMODE
        RGB As String * 94
    End Type
     
    Type type_DEVMODE
        chNomPériphérique As String * 16
        entSpécVersion As Integer
        entVersionGestionnaire As Integer
        entTaille As Integer
        entExtraGestionnaire As Integer
        lngChamps As Long
        entOrientation As Integer
        entTaillePapier As Integer
        entLongueurPapier As Integer
        entLargeurPapier As Integer
        entEchelle As Integer
        entCopies As Integer
        entSourceDéfaut As Integer
        entQualitéImpression As Integer
        entCouleur As Integer
        entRectoverso As Integer
        entResolution As Integer
        entOptionTT As Integer
        entAssembler As Integer
        entNomFormulaire As String * 16
        lngPad As Long
        lngBits As Long
        lngPW As Long
        lngPH As Long
        lngDFI As Long
        lngDFr As Long
    End Type
     
    Type ch_PRTMIP
        chRGB As String * 28
    End Type
     
    Type type_PRTMIP
        entMargeGauche As Long
        entMargeHaut As Long
        entMargeDroite As Long
        entMargeBas As Long
        entDonnéesSeulement As Long
        entLargeur As Long
        entHauteur As Long
        entTailleDesEléments As Long
        entColonnes As Long
        entEspacementDeColonnes As Long
        entEspacementDeLignes As Long
        entDisposition As Long
        entImpressionRapide As Long
        entFeuilleDeDonnées As Long
    End Type
    'Fin de section pour les Types nécessaires à la fonction ModifierMarges
     
    Public Sub ModifierMarges(txtNom As String, lngHaut As Long, lngBas As Long, lngGauche As Long, lngDroite As Long)
    ' Modifier les marges d'un rapport avant de l'imprimer
    ' paramètres : 1- le nom du rapport en texte
    ' 2- la marge du haut en cm
    ' 3- la marge du bas en cm
    ' 4- la marge du gauche en cm
    ' 5- la marge du droite en cm
    ' exemple :
    ' ModifierMarges "Contacts", 1, 1, 1.5, 1.5
    ' DoCmd.OpenReport "Contacts", acViewPreview
    Dim ChaînePrtMip As ch_PRTMIP
    Dim PM As type_PRTMIP
    Dim rpt As Report
    DoCmd.OpenReport txtNom, acDesign ' Ouvre l'état en mode Création.
    Set rpt = Reports(txtNom)
    ChaînePrtMip.chRGB = rpt.PrtMip
    LSet PM = ChaînePrtMip
    PM.entMargeHaut = lngHaut * 567 ' Définit les marges.
    PM.entMargeBas = lngBas * 567
    PM.entMargeGauche = lngGauche * 567
    PM.entMargeDroite = lngDroite * 567
    LSet ChaînePrtMip = PM ' Met à jour la propriété.
    rpt.PrtMip = ChaînePrtMip.chRGB
    DoCmd.Save
    End Sub
     
    Private Sub MaximizeRestoredReport(R As Report)
    'This code was originally written by Terry Kreft
    'Full credits and acknowledgements to him.
    '
    Dim MDIRect As RECT
        ' If the Report is maximized, restore it.
        If IsZoomed(R.hwnd) <> 0 Then
            ShowWindow R.hwnd, SW_SHOWNORMAL
        End If
     
        ' Get the screen coordinates and window size of the
        ' MDIClient area.
        'This is the line which is different
        GetClientRect GetParent(R.hwnd), MDIRect
     
        ' Move the Report to the upper left corner of the MDIClient
        ' window (0,0) and size it to the same size as the
        ' MDIClient window.
     
        MoveWindow R.hwnd, 0, 0, MDIRect.right - MDIRect.left, _
            MDIRect.bottom - MDIRect.top, True
    End Sub
     
    Sub sRemoveCaption(rpt As Report)
    Dim lngRet As Long, lngStyle As Long
    Dim tRECT As RECT, lngX As Long
    Dim lngCaptionWidth As Long
    Dim lngLeft As Long
    Dim lngTop As Long
    Dim lngWidth As Long
    Dim lngHeight As Long
     
        lngRet = apiGetWindowLong(rpt.hwnd, GWL_STYLE)
        lngStyle = (lngRet Xor WS_DLGFRAME Xor _
                        WS_THICKFRAME) And Not WS_CAPTION
        'Need the Xor above to keep window from being sizable
        lngRet = apiSetWindowLong(rpt.hwnd, GWL_STYLE, lngStyle)
        lngX = apiGetWindowRect(rpt.hwnd, tRECT)
     
        'have to resize the form now
        'how much was caption's screenspace
        lngCaptionWidth = apiGetSystemMetrics(SM_CYCAPTION)
     
        With tRECT
            lngLeft = .left
            lngTop = .top
            lngWidth = .right - .left
            lngHeight = .bottom - .top - lngCaptionWidth
            ConvertPIXELSToTWIPS lngLeft, lngTop
            ConvertPIXELSToTWIPS lngWidth, lngHeight
            DoCmd.SelectObject acReport, rpt.Name, False
            DoCmd.Restore
            DoCmd.MoveSize lngLeft, lngTop, lngWidth, lngHeight
        End With
     
        'now use Terry's code here
        Call MaximizeRestoredReport(rpt)
     End Sub
     
    Sub ConvertPIXELSToTWIPS(x As Long, Y As Long)
     'From the KB
        Dim hDC As Long, hwnd As Long, RetVal As Long
        Dim XPIXELSPERINCH, YPIXELSPERINCH
        Const LOGPIXELSX = 88
        Const LOGPIXELSY = 90
     
        hDC = apiGetDC(0)
        XPIXELSPERINCH = apiGetDeviceCaps(hDC, LOGPIXELSX)
        YPIXELSPERINCH = apiGetDeviceCaps(hDC, LOGPIXELSY)
        RetVal = apiReleaseDC(0, hDC)
        x = (x / XPIXELSPERINCH) * TWIPSPERINCH
        Y = (Y / YPIXELSPERINCH) * TWIPSPERINCH
    End Sub
    Pour imposer l'imprimante, il me semble que cette solution est donnée dans dans le tuto relatif à la génération des états en pdf car (de mémoire), c'est PDFWRITER qui est spécifiée.

    Bon courage !

  3. #3
    Membre expérimenté
    Avatar de Papy Turbo
    Homme Profil pro
    Développeur Office/VBA
    Inscrit en
    Mars 2004
    Messages
    822
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur Office/VBA
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2004
    Messages : 822
    Points : 1 709
    Points
    1 709
    Par défaut
    Belle solution pour Access 97 et 2000, mais peut être un peu compliquée pour Access 2002 (XP) et 2003, qui disposent d'un objet Printer pour l'application (= imprimante par défaut) + un objet Printer par état.
    Dans Access XP et 2003, tu peux donc spécifier :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    With Reports("État1").Printer
        .LeftMargin = 2500
        .BottomMargin = 2000
        [...] 
    End With
    ou toute autre valeur en Twips
    Voir l'aide Access sur l'objet Printer, + nombreux exemples et doc sur msdn, en anglais (chercher Access Printer object dans le moteur de msdn.microsoft.com, en faisant la recherche dans toutes les langues).

Discussions similaires

  1. Récupérer username + noms imprimantes utilisées
    Par cikky dans le forum VBScript
    Réponses: 1
    Dernier message: 02/12/2008, 16h20
  2. Réponses: 2
    Dernier message: 16/10/2005, 00h55
  3. Nom de partage d'une imprimante
    Par Tarek EZZAT dans le forum Langage
    Réponses: 1
    Dernier message: 07/09/2005, 21h10
  4. Noms des imprimantes installées
    Par bebeours dans le forum C++Builder
    Réponses: 3
    Dernier message: 06/11/2002, 15h57
  5. Connaitre le nom des imprimantes
    Par bastien dans le forum C++Builder
    Réponses: 3
    Dernier message: 10/06/2002, 16h36

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo