Bonjour,

J'ai un problème de syntaxe dans le code suivant :

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
Public Sub InsererDansWord4()
    'On Error Resume Next
' Déclaration des variables et des constantes
Dim strtype As String
Dim objWord As New Word.Application
Dim strNomPrenom As String
Dim strChambre As String

strNomPrenom = Forms.Commandes.Titre & " " & Forms.Commandes.Nomclient & " " & Forms.Commandes.Prenomclient

With objWord
        .Documents.Add Template:=CurrentProject.Path & "\resahotel.doc", NewTemplate:=False, DocumentType:=0

    If Not IsNull(strNomPrenom) Then .ActiveDocument.Bookmarks("Name").Range.Text = strNomPrenom
    Else: .ActiveDocument.Bookmarks("Name").Range.Text = "Champs Titre Nom Prénom non remplis"
    End If

        .ActiveDocument.Bookmarks("Numresa").Range.Text = Forms.Commandes.Factures.Form.IDfacture
        .ActiveDocument.Bookmarks("Numpax").Range.Text = Forms.Commandes.Numpax
        .ActiveDocument.Bookmarks("Date1").Range.Text = Forms.Commandes.Datedebut
        .ActiveDocument.Bookmarks("Date2").Range.Text = Forms.Commandes.Datefin
        .ActiveDocument.Bookmarks("Room").Range.Text = Forms.Commandes.Factures.Form.[RqTotalhotel subform].Form.Typechambre
        .ActiveDocument.Bookmarks("Nomhotel").Range.Text = Forms.Commandes.Factures.Form.[RqTotalhotel subform].Form.Nomhotel
        .ActiveDocument.Bookmarks("Adressehotel").Range.Text = Forms.Commandes.Factures.Form.[RqTotalhotel subform].Form.Adressehotel
        .ActiveDocument.Bookmarks("CPhotel").Range.Text = Forms.Commandes.Factures.Form.[RqTotalhotel subform].Form.CPVillehotel
        .ActiveDocument.Bookmarks("Telhotel").Range.Text = Forms.Commandes.Factures.Form.[RqTotalhotel subform].Form.Tel
        .ActiveDocument.Bookmarks("Numnuit").Range.Text = Forms.Commandes.Factures.Form.[RqTotalhotel subform].Form.Numnuit
        
'affichage en plein écran
.WindowState = wdWindowStateMaximize

'lance la boite de dialogue d'enregistrement du document
With .Dialogs.Item(wdDialogFileSaveAs)
    .Name = "Z:\CLIENTS PROPOSITIONS\"
    'si on clique sur enregistrer... sinon...
    If .Show = -1 Then
    MsgBox "Document enregistré"
    Else
    objWord.Quit savechanges:=False
    MsgBox "Vous avez annulé l'enregistrement!"
    End If
End With
End With
'en cas de modification de l'enregistrement, on sauvegarde
If Dirty = True Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
End If
'Libération de l'objet
    Set objWord = Nothing
End Sub
La fonction If Not IsNull que j'ai mis ici en rouge ne réponds pas comme je le souhaite. A vrai dire, si je laisse ainsi sur plusieurs lignes, j'ai le message d'erreur : " 'Else' sans 'If' " et si je mets l'ensemble sur une seule ligne, c'est Erreur de syntaxe.
Le but serait d'avoir au niveau du signet dans Word soit le contenu des champs si les champs ne sont pas vides, soit le texte "Champs Titre Nom Prénom non remplis"
Quelqu'un pourrait-il me dire comment rédiger correctement cette ligne de code ?
Merci par avance