Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Access > VBA Access
VBA Access Le forum pour les questions relatives au code VBA sous Access, et à son environnement de développement VBE.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 04/04/2011, 16h44   #1
Invité de passage
 
Inscription : juillet 2009
Messages : 21
Détails du profil
Informations forums :
Inscription : juillet 2009
Messages : 21
Points : 1
Points : 1
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 :
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
selverine est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/04/2011, 16h54   #2
Rédacteur/Modérateur
 
Avatar de GAYOT
 
Homme Jean-Damien GAYOT
Inscription : novembre 2004
Messages : 2 071
Détails du profil
Informations personnelles :
Nom : Homme Jean-Damien GAYOT
Âge : 56
Localisation : France, Meuse (Lorraine)

Informations professionnelles :
Secteur : Distribution

Informations forums :
Inscription : novembre 2004
Messages : 2 071
Points : 4 367
Points : 4 367
Envoyer un message via Skype™ à GAYOT
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/
__________________
Plus j'avance et plus j'ai l'impression de ne rien savoir. Et comme j'essaie d'aller loin..!!.

Tutoriels sur:http://jdgayot.developpez.com

Pas de sujets techniques par Mp. Sinon
GAYOT est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/04/2011, 16h59   #3
Invité de passage
 
Inscription : juillet 2009
Messages : 21
Détails du profil
Informations forums :
Inscription : juillet 2009
Messages : 21
Points : 1
Points : 1
Ah j'était même pas au courant.

J'utilise Microsoft Access 2007

Je regarde le site tout de suite
selverine est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/04/2011, 17h39   #4
Rédacteur/Modérateur
 
Avatar de GAYOT
 
Homme Jean-Damien GAYOT
Inscription : novembre 2004
Messages : 2 071
Détails du profil
Informations personnelles :
Nom : Homme Jean-Damien GAYOT
Âge : 56
Localisation : France, Meuse (Lorraine)

Informations professionnelles :
Secteur : Distribution

Informations forums :
Inscription : novembre 2004
Messages : 2 071
Points : 4 367
Points : 4 367
Envoyer un message via Skype™ à GAYOT
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.
__________________
Plus j'avance et plus j'ai l'impression de ne rien savoir. Et comme j'essaie d'aller loin..!!.

Tutoriels sur:http://jdgayot.developpez.com

Pas de sujets techniques par Mp. Sinon
GAYOT est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/04/2011, 20h19   #5
Invité de passage
 
Inscription : juillet 2009
Messages : 21
Détails du profil
Informations forums :
Inscription : juillet 2009
Messages : 21
Points : 1
Points : 1
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é!
selverine est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 05h17.


 
 
 
 
Partenaires

Hébergement Web