Bonjour,

J'ai un petit problème avec VB6. En fait, je souhaite imprimer une feuille "historique" d'outils qui se présente un peu à la manière d'une facture : l'entête et les lignes de commande.
L'entête dépend des textbox de ma Form et les lignes, c'est un recordset (rs_histo).

J'ai donc ce code pour imprimer sous Word :

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
Private Sub b_imprim_Click()
    Dim MyWord As Word.Application
    Dim rs_histo As Recordset
    Dim sql_histo As String
 
'ouverture du recordset
        Set rs_histo = New ADODB.Recordset
        rs_histo.CursorType = adOpenDynamic
        rs_histo.CursorLocation = adUseClient
        sql_histo = "select D_ETALON,NUM_CERT,VERIF,OBSERV, COUT_ETALON from DBETALON WHERE NUM_OUTILS='" & Frm_outils.MSFlexGrid1.Text & "' order by D_ETALON"                        'Affichage de la requête
        rs_histo.Open sql_histo, cn, adOpenDynamic, adLockOptimistic
        rs_histo.MoveFirst
 
 
    Set MyWord = New Word.Application
 
            With MyWord
                .Documents.Open ("D:\Application\Visual Basic 6.0\VB98\GDE2008\TEST.doc")
                .Visible = False        
                .ActiveDocument.Bookmarks("date_jour").Range.Text = date_jour.Value
                .ActiveDocument.Bookmarks("designation").Range.Text = design.Text
                .ActiveDocument.Bookmarks("etalon").Range.Text = design.Text
                .ActiveDocument.Bookmarks("identification").Range.Text = numero.Text
                .ActiveDocument.Bookmarks("type").Range.Text = type_outils.Text
                .ActiveDocument.Bookmarks("marque").Range.Text = marque.Text
                .ActiveDocument.Bookmarks("service").Range.Text = service.Text
                .ActiveDocument.Bookmarks("affectation").Range.Text = affect.Text
                .ActiveDocument.Bookmarks("periodicite").Range.Text = frequence.Text
                .ActiveDocument.Bookmarks("prestataire").Range.Text = respetalon.Text
                .ActiveDocument.Bookmarks("etal").Range.Select
                Do Until rs_histo.BOF = True Or rs_histo.EOF = True
                    Selection.MoveRight (wdCell) '=> le débogage s'arrete là après un 2ème clic sur le bouton
                    Selection.TypeText (rs_histo.Fields(0))
                    Selection.MoveRight (wdCell)
                    Selection.TypeText (rs_histo.Fields(1))
                    Selection.MoveRight (wdCell)
                    Selection.TypeText (rs_histo.Fields(2))
                    Selection.MoveRight (wdCell)
                    Selection.TypeText (rs_histo.Fields(3))
                    Selection.MoveRight (wdCell)
                    Selection.TypeText (rs_histo.Fields(4))
                    rs_histo.MoveNext
                Loop
                End With
                MyWord.ActiveDocument.PrintOut
                MyWord.ActiveDocument.Close (wdDoNotSaveChanges)
            DoEvents
            Set MyWord = Nothing
            rs_histo.Close
End Sub
Je place mes valeurs de TextBox sur mes signet Word et pour le recordset, je place un signet dans la dernière cellule de ma ligne d'entète, je le sélectionne et je "move right" pour créer un nouvelle ligne. Je répète ça jusqu'à ce que tout mes enregistrements soient inscrit.

Et ca marche très bien... la première fois. Mais si je souhaite imprimer de nouveau, j'ai ce message :

Erreur d'éxécution '91':

Variable objet ou variable bloc With non définie
et le débogage m'ammène sur la ligne juste en dessous de DO UNTIL :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
Selection MoveRight (wdCell)
Help me please

D'avance, merci.