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

VBA Access Discussion :

Créer un PDF avec PDFCreator


Sujet :

VBA Access

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2009
    Messages
    28
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2009
    Messages : 28
    Par défaut Créer un PDF avec PDFCreator
    Bonjour,

    Je souhaite créer un PDF avec PDFCreator à l'aide de VB.
    Dans ce PDF je souhaiterai écrire des variables que je récupère soit directement de Access, soit d'un .txt (file.txt ).

    Pour l'instant j'ai ce code (voir ci-dessous):
    Mon problème viens de cette ligne là: DoCmd.OpenReport (sReportName).
    J'ai une erreur.
    Puis-je passer en paramètre un fichier .txt ou des variables? ou faut il utiliser d'autre fonction?

    Merci par avance!

    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
    Dim pdfjob As PDFCreator.clsPDFCreator
        
        Dim sPDFName As String
        Dim sPDFPath As String
        Dim sPrinterName As String
        Dim sReportName As String
        Dim lPrinters As Long
        Dim lPrinterCurrent As Long
        Dim lPrinterPDF As Long
        Dim prtDefault As Printer
    
        '/// Change the report and output file name here! ///
        sReportName = "file.txt"
        sPDFName = "test.pdf"
        sPDFPath = "c:\"
    
        'Resolve index number of printers to allow changing and preserving
        sPrinterName = Application.Printer.DeviceName
        On Error Resume Next
        For lPrinters = 0 To Application.Printers.Count
            Set Application.Printer = Application.Printers(lPrinters)
    
            Set prtDefault = Application.Printer
            Select Case prtDefault.DeviceName
                Case Is = sPrinterName
                    lPrinterCurrent = lPrinters
                Case Is = "PDFCreator"
                    lPrinterPDF = lPrinters
                Case Else
                    'do nothing
            End Select
        Next lPrinters
        On Error GoTo 0
        
            'Change the default printer
        Set Application.Printer = Application.Printers(lPrinterPDF)
        Set prtDefault = Application.Printer
       'Start PFF Creator
        Set pdfjob = New PDFCreator.clsPDFCreator
        With pdfjob
             If .cStart("/NoProcessingAtStartup") = False Then
                MsgBox "Can't initialize PDFCreator.", vbCritical + _
                        vbOKOnly, "PrtPDFCreator"
                Exit Sub
             End If
            .cOption("UseAutosave") = 1
            .cOption("UseAutosaveDirectory") = 1
            .cOption("AutosaveDirectory") = sPDFPath
            .cOption("AutosaveFilename") = sPDFName
            .cOption("AutosaveFormat") = 0    ' 0 = PDF
            .cClearCache
        End With
    
     'Print the document to PDF
        DoCmd.OpenReport (sReportName)
     
       
       addDocument file.txt
        'Wait until the print job has entered the print queue
        Do Until pdfjob.cCountOfPrintjobs = 1
            DoEvents
        Loop
        pdfjob.cPrinterStop = False
    
        'Wait until PDF creator is finished then release the objects
        Do Until pdfjob.cCountOfPrintjobs = 0
            DoEvents
        Loop
        pdfjob.cClose
    
        'Reset the (original) default printer and release PDF Creator
        Set Application.Printer = Application.Printers(lPrinterCurrent)
        Set pdfjob = Nothing

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour
    Il est important de mentionner la version utilisée. En effet à partir de 2007 tu peux le faire sans passer par PdfCreator.
    Sinon as tu lu ceci?
    http://cafeine.developpez.com/access/tutoriel/pdf/

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2009
    Messages
    28
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2009
    Messages : 28
    Par défaut
    Ah j'était même pas au courant.

    J'utilise Microsoft Access 2007

    Je regarde le site tout de suite

  4. #4
    Invité
    Invité(e)
    Par défaut
    Si c'est en 2007, lis plutôt ce tuto:
    http://warin.developpez.com/access/pdf/

    Prends la deuxième partie sur le chapitre III-B, puisque il n'y a plus besoin de l'extension.

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2009
    Messages
    28
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2009
    Messages : 28
    Par défaut
    Merci beaucoup! Ca marche super bien!

    J'ai juste du installer un ptit truc pour que la commande marche
    (http://www.eggheadcafe.com/software/...ing-twice.aspx)

    En tout cas merci de ton aide et de ta rapidité!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 4
    Dernier message: 30/06/2015, 00h47
  2. taille pdf avec pdfcreator
    Par looping dans le forum Autres Logiciels
    Réponses: 1
    Dernier message: 29/08/2007, 11h55
  3. [VBA-W]Imprimer doc vers pdf avec pdfcreator
    Par Mut dans le forum VBA Word
    Réponses: 2
    Dernier message: 08/12/2006, 14h39
  4. Réponses: 1
    Dernier message: 24/05/2006, 18h29
  5. [VB6] Créer un .PDF avec VB ?
    Par Vince dans le forum VB 6 et antérieur
    Réponses: 3
    Dernier message: 21/07/2005, 14h27

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