Bonjour,

J'ai un programme d'impression qui me génère aléatoirement mais toujours au même endroit dans le code l'erreur suivante :
Erreur 484 : Problème pour obtenir des informations du gestionnaire d'imprimante du système. Assurez-vous que l'imprimante est bien configurée.

Voici la procédure concernée :

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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
 
Sub Traite_Intro(ByVal Intro As String, ByVal fic As String, ByVal Ligne As Long, _
    ByVal page As Long, ByVal ind1 As Long, ByVal ind2 As Long, ByVal num As Long)
 
    Dim diago As Long, Data As String, Hora As String, Utilisateur As String, _
    Ecran As String, ind As Long, Bac As Long, Mode As Long, TypeEd As String, _
    TypeInt As String, PtInt As String, Texte As String
 
    Dim RectoVerso As Boolean
    Dim Recset As Recordset
 
    On Error GoTo Err
 
    Printer.EndDoc ' [STEPH] Evite l'erreur VB5 396
    Sleep (100)
    If Left(Intro, 3) <> "/$/" Then
        diago = 22
        PtInt = 5 / 0
    End If
    Mode = -1
    Impr = ""
    ' Jour de création du fichier
    diago = 1
    Data = Mid(Intro, 4, 8)
    ' Heure de création du fichier
    diago = 2
    Hora = Mid(Intro, 12, 6)
    ' Nom de l'utilisateur
    diago = 3
    Utilisateur = Mid(Intro, 18, 10)
    ' Nom de l'écran AS400
    diago = 4
    Ecran = Mid(Intro, 28, 10)
 
    Dim f As Form
    If SpecifImprimante = "" Then
        Set f = SRVIMPR
    Else
        Set f = f_MultiTache
    End If
 
    ' Joker
    Dim Joker As String
    Joker = Mid(Intro, 130, 6)
    If Trim(Joker) <> "" Then
        Cont_P = CLng(Joker)
        f.Set_Status ("Impression de la page " & Cont_P & " sur " & Imp_Current)
    End If
 
 
    ' Configuration de l'imprimante à utiliser
    If Impri <> "" Then      ' Réalise la boucle uniquement au premier passage dans cette procédure
        Impr = esp(Impri, 10)
        Imp_Current = Impr
    Else
        diago = 15
        Impr = UCase(Mid(Intro, 38, 10))   ' La procédure prend l'imprimante spécifiée dans le fichier
'        ##### Retrait pour test #####
        ' MODIF du 16/9/04 et on rajoute ce qu'il y a en position 70-72 pour les imprimantes spéciales PDFs
 
        ' [Steph] modif condition IF
        If UCase(Mid$(Intro, 70, 3)) <> "" Then
            Impr = Trim(Impr) + UCase(Mid$(Intro, 70, 3))
            diago = 5
        End If
        Logger ("Imprimante dans le fichier : '" & Trim(Impr) & "'")
        ' Récupère le numéro associé, à l'imprimante choisie, pour le PC
        Set Recset = DB.OpenRecordset("SELECT nom, id_theme, rectoverso FROM imprimante WHERE utilisateur='" & Trim(Impr) & "'")
        ' Si on ne récupère rien , on fait un saut à la fin et on enregistre
        ' les éléments récupérés et le diagnostic d'échec.
        If Recset.RecordCount = 0 Then
            GoTo Err
        End If
'       #############################################
'       Modif du 09/11/04 : Ajout pour traiter l'imprimante avec le job
'        diago = 16
'        TypeEd = Mid(Intro, 50, 3)
'       '
'        If UCase(Mid$(Intro, 70, 3)) = "" Then
'            Set RecSet = DB.OpenRecordset("SELECT intitule FROM Traitement WHERE code ='" & TypeEd & "'")
'            ' Récupère le numéro associé, à l'imprimante choisie, pour le PC
'            ' Si on ne récupère rien , on fait un saut à la fin et on enregistre
'            ' les éléments récupérés et le diagnostic d'échec.
'            If RecSet.RecordCount = 1 Then
'                TypeEd = RecSet.Fields("intitule").Value
'                RecSet.Close
'                Set RecSet = DB.OpenRecordset("SELECT nom, id_theme, rectoverso FROM imprimante_new WHERE utilisateur='" & Trim(Impr) & "' AND intitule ='" & TypeEd & "'")
'                If RecSet.RecordCount = 0 Then
'                    GoTo Err
'                End If
'                Imp_Current = Impr
'            End If
'            Impr = Imp_Current
'            diago = 5
'            Logger ("Imprimante dans le fichier : '" & Trim(Impr) & "'")
'        Else
'           Imp_Current = Trim(Impr)
'            diago = 5
'            TypeEd = "Defaut"
'            Logger ("'Imprimante dans le fichier : '" & Trim(Impr) & "'")
'            ' Récupère le numéro associé, à l'imprimante choisie, pour le PC
'            Set RecSet = DB.OpenRecordset("SELECT nom, id_theme, rectoverso FROM imprimante_new WHERE utilisateur='" & Trim(Impr) & "' AND intitule ='" & TypeEd & "'")
'            ' Si on ne récupère rien , on fait un saut à la fin et on enregistre
'            ' les éléments récupérés et le diagnostic d'échec.
'            If RecSet.RecordCount = 0 Then
'                GoTo Err
'            End If
'        End If
'       #############################################
        '
        ' CHANGEMENT D'IMPRIMANTE
        'Change_Printer RecSet.Fields("nom").Value, Printer
        Dim Prt_Tmp As Printer
 
        ' on doit maintenant récupérer le theme à utiliser
        id_Theme = Recset.Fields("id_theme").Value
        diago = 21
        Logger ("Avant utilisation du theme : " & id_Theme)
        Use_Theme id_Theme
        diago = 5
 
        RectoVerso = Recset.Fields("rectoverso").Value
        Logger ("Recherche de l'imprimante dans Windows : '" & Recset.Fields("nom").Value & "'")
        For Each Prt_Tmp In Printers
            If UCase(Prt_Tmp.DeviceName) = UCase(Recset.Fields("nom").Value) Then
                Set Printer = Prt_Tmp
'                Printer.PrintQuality = vbPRPQHigh
                Logger ("Impression sur : '" & Recset.Fields("nom").Value & "'")
 
#If 1 Then
    ' BONNE VERSION MAIS CASSE TOUT CHEZ SERY !
                If Norm_PaperSize >= 0 Then
                    ' Pour debug, on récupère les valeurs avant changement !
                    Logger ("Norm_PaperSize = " & Norm_PaperSize & " / Printer.width = " & Printer.Width & " / Printer.height = " & Printer.Height)
                    diago = 23
                    If Norm_PaperSize = 256 Then
                        On Error GoTo Err_PaperSize
                        Printer.PaperSize = Norm_PaperSize
                        GoTo Suite_PaperSize
Err_PaperSize:
                        Logger ("Erreur (ou avertissement) détecté pendant changement de Papersize à 256")
                        Resume Suite_PaperSize
Suite_PaperSize:
 
                        On Error GoTo Err  ' on se remet au mode normal
                        Logger ("Taille demandé  : " & Norm_PapersizeX & " / " & Norm_PapersizeY)
                        Printer.Width = Norm_PapersizeX
                        Printer.Height = Norm_PapersizeY
                        Logger ("Taille après modification : " & Printer.Width & " / " & Printer.Height)
                    Else
                        Logger ("Taille demandé : " & Norm_PaperSize)
                        Printer.PaperSize = Norm_PaperSize
                    End If
                    diago = 5
                Else
                    Logger ("Taille non modifié : " & Printer.Width & " / " & Printer.Height)
                End If
#Else
    ' ANCIENNE VERSION: ne comptait pas du compte de la taille de document indiqué dans POLICE.MDB
                        ' mais celle indiqué après le nom d'imprimante !!!!!!
                Printer.PaperSize = PaperSize
                If PaperSize = 256 Then
                    Printer.Width = Norm_PapersizeX
                    Printer.Height = Norm_PapersizeX
                End If
#End If
                Dim T
                If Marge_Haute <> 0 Then
                    T = Printer.ScaleMode
                    Printer.ScaleMode = vbMillimeters
                    Printer.CurrentY = Marge_Haute
                    Printer.ScaleMode = T
                End If
                If Marge_Gauche <> 0 Then
                    T = Printer.ScaleMode
                    Printer.ScaleMode = vbMillimeters
                    Printer.CurrentX = Marge_Gauche
                    Printer.ScaleMode = T
                    ' on récupère la marge gauche en mode Twips
                    Marge_GaucheTwips = Printer.CurrentX
                Else
                    Marge_GaucheTwips = 0
                End If
            End If
        Next
        Recset.Close
    End If
    ' On ajuste la marge selon l'imprimante choisie avec comme étalon, une ligne complète
    Printer.ScaleWidth = Printer.Width
    Printer.ScaleMode = vbTwips
    ' Configuration du bac imprimante à utiliser
    diago = 11
    If Baci = 999 Then  'Valeur pour laquelle il n'y a pas eu de choix de la part de l'utilisateur
                        'On récupère le numéro de bac dans l'enregistrement Bac & Mid(Intro, 48, 1)
                        'Sinon, la propriété PaperBin a déjà été affectée lors du choix de l'imprimante
                        'Pour la réimpression
        'Set RecSet = DB.OpenRecordset("select Bac" & Mid(Intro, 48, 1) & " from imprimante_new where utilisateur='" & Trim(Impr) & "' AND intitule ='" & TypeEd & "'")
        Set Recset = DB.OpenRecordset("select Bac" & Mid(Intro, 48, 1) & " from imprimante where utilisateur='" & Trim(Impr) & "'")
        Bac = CLng(Left(Recset.Fields("Bac" & Mid(Intro, 48, 1)).Value, 6))
        Recset.Close
        diago = 12
        Printer.PaperBin = Bac
        Bac = Mid(Intro, 48, 1)
        Logger ("Bac utilisé : " & Bac)
    Else
        Bac = Baci
    End If
 
    ' configuration du mode recto-verso
    diago = 13
    If RecVer = 0 Or RecVer = 1 Then  'Valeur pour lesquels, le choix d'imprimante pour la réimpression
    ' a déjà affecté la prop Duplex
        Mode = RecVer
    Else        'Première impression ou aucun choix RecVer de l'uti
        If Mid(Intro, 49, 1) = "N" Then
            Logger ("Recto Verso : désactivé")
            diago = 14
            Mode = 0
            Printer.Duplex = 1
        Else
            diago = 14
            Mode = 1
            If RectoVerso = True Then
                Logger ("Recto Verso : activé")
                Printer.Duplex = 2
            Else
                Logger ("Recto Verso : demandé mais désactivé")
                Printer.Duplex = 1
            End If
        End If
    End If
    ' autre à traiter
    diago = 16
    TypeEd = Mid(Intro, 50, 3)
    diago = 17
    TypeInt = Mid(Intro, 53, 2)
    diago = 18
    PtInt = Mid(Intro, 55, 11)
    diago = 19
    Texte = Mid(Intro, 66, 4)
 
    ' Toutes les étapes ont réussies
    If num = 0 Then                ' insertion pour impression
        If ind2 > 1 Then
            Histo.Execute ("update historique set p2=" & page - 1 & " where num1=" & ind1 & " and num2=" & ind2 - 1)
            If Histo.RecordsAffected <> 1 Then
                Logger ("Erreur lors de l'insertion")
            End If
        End If
        Histo.Execute ("insert into historique (num1,num2,Jour,Heure,DateI,HeureI,NomImpr,TypeEdition" & _
            ",TypeIntervenant,Utilisateur,NomEcran,Texte,NomFichier," & _
            "Diagnostic,Bac,Mode,P1,P2,lig) values (" & ind1 & "," & ind2 & ",'" & Data & "','" & Hora & "','" & _
            Format(Date, "dd/mm/yyyy") & "','" & Format(time, "hh:mm:ss") & "','" & _
            Impr & "','" & TypeEd & "','" & TypeInt & "','" & Utilisateur & "','" & _
            Ecran & "','" & Texte & "','" & fic & "',0," & Bac & "," & Mode & "," & page & ",0," & Ligne & ")")
        If Histo.RecordsAffected <> 1 Then
            Logger ("Erreur lors de l'insertion")
        End If
    ElseIf num = 1 Or num = 2 Then          ' Mise à Jour pour Ré-Imp (sauf par page)
'        If num = 6 Then
        ' on vérifie d'abord qu'il y ait bien un couplet (num1,num2)
        Dim s As String, o As Recordset
        s = "SELECT num1 FROM historique WHERE num1=" & ind1 & " AND num2=" & ind2
        Set o = Histo.OpenRecordset(s, dbOpenSnapshot)
        If o.RecordCount = 0 Then
            If ind2 > 1 Then
                Histo.Execute ("update historique set p2=" & page - 1 & " where num1=" & ind1 & " and num2=" & ind2 - 1)
            End If
            Histo.Execute ("insert into historique (num1,num2,Jour,Heure,DateI,HeureI,NomImpr,TypeEdition" & _
                ",TypeIntervenant,Utilisateur,NomEcran,Texte,NomFichier," & _
                "Diagnostic,Bac,Mode,P1,P2,lig) values (" & ind1 & "," & ind2 & ",'" & Data & "','" & Hora & "','" & _
                Format(Date, "dd/mm/yyyy") & "','" & Format(time, "hh:mm:ss") & "','" & _
                Impr & "','" & TypeEd & "','" & TypeInt & "','" & Utilisateur & "','" & _
                Ecran & "','" & Texte & "','" & fic & "',0," & Bac & "," & Mode & "," & page & ",0," & Ligne & ")")
        End If
        o.Close
 
 
        Histo.Execute "update historique set DateI='" & Format(Date, "dd/mm/yyyy") & "'," & _
        "HeureI='" & Format(time, "hh:mm:ss") & "'," & _
        "nomimpr='" & Impr & "',Typeedition='" & TypeEd & "',TypeIntervenant='" & TypeInt & _
        "',Nomecran='" & Ecran & "',Texte='" & Texte & _
        "',diagnostic=0 ,bac=" & Bac & ",mode=" & Mode & " where num1=" & ind1 & " and num2=" & ind2
        If Histo.RecordsAffected <> 1 Then
            Logger ("Erreur lors de l'insertion")
        End If
    End If
    Logger ("Fin de Traite_Intro (sans erreur)")
    Exit Sub
Err:              ' insertion ou update dans la base, après récup mode R/V
    Logger ("Erreur détecté : " & diago)
 
    If Mode = -1 And (RecVer = 3 Or RecVer = 4) Then      'en cas d'échec avant le mode RV on récupère quel été celui ci
        If Mid(Intro, 49, 1) = "N" Then
            Mode = 0
        Else
            Mode = 1
        End If
    Else
        Mode = RecVer
    End If
    If num = 0 Then
        If ind2 > 1 Then
            Histo.Execute ("update historique set p2=" & page - 1 & " where num1=" & ind1 & " and num2=" & ind2 - 1)
            If Histo.RecordsAffected <> 1 Then
                Logger ("Erreur lors de l'insertion")
            End If
        End If
        Histo.Execute ("insert into historique (num1,num2,Jour,Heure,DateI,HeureI,NomImpr,TypeEdition" & _
            ",TypeIntervenant,Utilisateur,NomEcran,Texte,NomFichier," & _
            "Diagnostic,Bac,Mode,P1,P2,lig) values (" & ind1 & "," & ind2 & ",'" & Data & "','" & Hora & "','" & _
            Format(Date, "dd/mm/yyyy") & "','" & Format(time, "hh:mm:ss") & "','" & _
            Impr & "','" & TypeEd & "','" & TypeInt & "','" & Utilisateur & "','" & _
            Ecran & "','" & Texte & "','" & fic & "'," & diago & "," & Bac & "," & Mode & "," & page & ",0," & Ligne & ")")
            If Histo.RecordsAffected <> 1 Then
                Logger ("Erreur lors de l'insertion : ")
            End If
    ElseIf num = 1 Or num = 2 Then
        Histo.Execute "update historique set DateI='" & Format(Date, "dd/mm/yyyy") & "'," & _
        "HeureI='" & Format(time, "hh:mm:ss") & "'," & _
        "nomimpr='" & Impr & "',Typeedition='" & TypeEd & "',TypeIntervenant='" & TypeInt & _
        "',Nomecran='" & Ecran & "',Texte='" & Texte & _
        "',diagnostic=" & diago & ",bac=" & Bac & ",mode=" & Mode & " where num1=" & ind1 & " and num2=" & ind2
        If Histo.RecordsAffected <> 1 Then
            Logger ("Erreur lors de l'insertion")
        End If
    End If
    Impr = ""
End Sub
La ligne qui a l'air de générer l'erreur apparemment est "Printer.PaperSize = Norm_PaperSize" mais je ne suis pas certain.
Avez-vous déjà eu ce problème ? Pourquoi cette erreur est-elle aléatoire et surtout pourquoi elle est intervient ?

Merci parce que là je ne comprends pas du tout.