Access PDF-Datei ausgefüllt speichern

Hallo!

Ich habe ein kleines Problem und hoffe ihr könnt mir helfen.
Ich sitze momentan an einem Access-Programm, indem ich gerne ein Datenblatt (PDF-Formular) an jeden Auftrag hängen möchte. Die PDF-Datei sollte dann unter dem Namen eines bestimmten Feldes(Auftragsnummer) meines Access-Programmes angelegt werden. Es müsste quasi eine Abfrage geben: Wenn PDF-datei mit dem Namen voranden dann öfnnen sonst eine anlegen mit dem Namen. Wie kann ich das umsetzen?
Und vielleicht ncoh eine weitere Frage: Ich habe mich schon etwas umgesehen und lese immer mal wieder das man PDF-Formulare ausgefüllt nicht speichern kann. Ist das so richtig?

Mit freundlichen Grüßen

Hallo!

Das habe ich in einem meiner Programme gelöst. Du musst nur die Felder umbenennen.

LG
Martin

Public Sub ExportPDF(ByVal ValKNummer As String, ByVal ValBelegNr As String, ByVal ValGroupText As String, ByVal ValReport As String)
'---------------------------------------------------------------------------------------
’ Procedure : ExportPDF
’ Author : Martin Sachers
’ Date : 10.10.2011
’ Purpose : Druckt den Beleg als PDF aus. Falls der Beleg schon vorhanden ist und noch
’ einmal erzeugt wurde dann überspeichere ihn mit dem aktuellen Datum, im Dateisystem ebenso wie im DMS
'---------------------------------------------------------------------------------------

Dim strNeu As String
Dim strDate As String
Dim strPath As String
Dim cd As ADODB.Command
Dim strDocNrNeu As String

On Error GoTo err_Gearwheel

strDate = Date
strPath = mavGetSQLValue(„SELECT PathBelege FROM dbo.tblModule WHERE ModulID = 3“)
strOutputFile = strPath + „“ + ValGroupText + ValBelegNr + „.pdf“

DoCmd.OutputTo acOutputReport, ValReport, acFormatPDF, strOutputFile, True, False, False, acExportQualityPrint

Set cd = New ADODB.Command
cd.ActiveConnection = CurrentProject.Connection
cd.CommandType = adCmdText

’ Prüfen ob der Beleg schon einmal im DMS gespeichert wurde:
Dim intCount As Integer
intCount = mavGetSQLValue(„SELECT COUNT(*) FROM dbo.tblDoc WHERE (KNummer=“ & ValKNummer & „) AND (BelegNr=“ & ValBelegNr & „)“)
If intCount = 0 Then
If mavGetSQLValue("SELECT COUNT(*) FROM dbo.tblDoc WHERE (DocPfad IS NULL) ") > 0 Then
'Es gibt noch freie Doc-Nummern:
strNeu = mavGetSQLValue(„SELECT TOP(1) DocID FROM dbo.tblDoc WHERE (DocPfad IS NULL)“)
cd.CommandText = „UPDATE dbo.tblDoc SET Autor=“ _

  • strAnwenderID _
  • „,KNummer=“ _
  • ValKNummer _
  • „,DocPfad=’“ _
  • strOutputFile _
  • „’, DocDatum=’“ _
  • strDate _
  • „’, BelegNr=“ _
  • ValBelegNr _
  • " WHERE DocID = " _
  • strNeu
    Else
    'Es gibt keine freien Doc-Nummern mehr!
    strDocNrNeu = mavGetSQLValue(„SELECT isnull(MAX(DocID)+1,1) FROM dbo.tblDoc“)
    cd.CommandText = „INSERT INTO dbo.tblDoc (DocID, Autor, KNummer, DocPfad, DocDatum, BelegNr, BetriebsID) VALUES (“ _
  • strDocNrNeu + „,“ _
  • strAnwenderID + „,“ _
  • ValKNummer + „,’“ _
  • strOutputFile + „’,’“ _
  • strDate + „’,“ _
  • ValBelegNr + „,“ _
  • strBetriebsID + „)“
    End If
    cd.Execute
    Else
    ‚Der Beleg wurde schon mal gespeichert. Nun wird nur das aktuelle Datum gesetzt!
    cd.CommandText = "UPDATE dbo.tblDoc SET DocDatum=‘" & CStr(Date) & „’ WHERE (KNummer=“ & ValKNummer & „) AND (BelegNr=“ & ValBelegNr & „)“
    cd.Execute
    End If

'Gilt für neue Belege als auch solche deren Datum nur aktualisiert wird:
’ Call MsgBox(„Der Beleg wurde sowohl im Verzeichnis " + strPath + " als auch im DMS erfolgreich gespeichert!“, vbInformation Or vbSystemModal, Application.Name)
Call MsgBox("Der Beleg wurde sowohl im Verzeichnis " _
& vbCrLf _
& strPath _
& vbCrLf & „als auch im DMS erfolgreich gespeichert!“ _
, vbInformation Or vbSystemModal, Application.Name)

exit_Gearwheel:
Set cd = Nothing
Exit Sub
err_Gearwheel:
Select Case Err.Number
Case 0
Resume exit_Gearwheel
Case 2501
Resume exit_Gearwheel 'Druck Bericht abgebrochen
Case Else
MsgBox Err.Number + Err.Description
Resume exit_Gearwheel
End Select
End Sub

Danke für die schnelle Antwort.
Das sieht echt sehr komplex und schwierig aus. Ich weiß gar nicht wo ich anfangen soll. Gibt es nicht eine einfachere Möglichkeit?
Mir fällt es schwer den Code auf meine wünsche anzupassen. Ich glaube einiges davon benötige ich auch nicht

Hier eine minierte Version:

Public Sub ExportPDF(ByVal ValAuftragsnummer As String)
'Das ganze ist in ADO geschrieben. Du kannst es Dir nach DAO portieren.

Dim strNeu As String
Dim strDate As String
Dim strPath As String
Dim cd As New ADODB.Command
Dim strDocNrNeu As String
Dim intCount As Integer

’ Die PDF-Datei sollte dann unter dem Namen eines bestimmten Feldes(Auftragsnummer)

On Error GoTo err_Gearwheel

strDate = Date
strPath = „DeinPfad“
strOutputFile = strPath + „“ + ValAuftragsnummer + „.pdf“

DoCmd.OutputTo acOutputReport, „DeinBericht“, acFormatPDF, strOutputFile, True, False, False, acExportQualityPrint

’ Prüfen ob der Beleg schon einmal im DMS gespeichert wurde:

intCount = mavGetSQLValue(„SELECT COUNT(*) FROM dbo.tblDoc WHERE (Auftragsnummer=“ & ValAuftragsnummer +")")
If intCount = 0 Then
strDocNrNeu = mavGetSQLValue(„SELECT isnull(MAX(DocID)+1,1) FROM dbo.tblDoc“)
cd.ActiveConnection = CurrentProject.Connection
cd.CommandType = adCmdText
cd.CommandText = „INSERT INTO dbo.tblDoc (DocID, Auftragsnummer) VALUES (“ _

  • strDocNrNeu + „,“ _
  • ValAuftragsnummer + „)“
    cd.Execute
    End If
    set cd=nothing
    End Sub

Okay. Ich probiere es nachher mal aus.
Was bedeutet ADO und DAO?

Wie Du auf die Datensätze zugreifst. Ich habe meine Datenbank auf einem SQL Server und greife daher mit ADO darauf zu. Du hast Deine Daten wahrscheinlich in Access direkt und greifst mit DAO darauf zu.

Ja das stimmt ist alles in eine Datenbank. Und was muss ich ändern?

Ohne Gewähr:
Dim strNeu As String
Dim strDate As String
Dim strPath As String
Dim strDocNrNeu As String
Dim intCount As Integer

’ Die PDF-Datei sollte dann unter dem Namen eines bestimmten Feldes(Auftragsnummer)

On Error GoTo err_Gearwheel

strDate = Date
strPath = „DeinPfad“
strOutputFile = strPath + „“ + ValAuftragsnummer + „.pdf“

DoCmd.OutputTo acOutputReport, „DeinBericht“, acFormatPDF, strOutputFile, True, False, False, acExportQualityPrint

’ Prüfen ob der Beleg schon einmal im DMS gespeichert wurde:

intCount = currentdb.execute(„SELECT COUNT(*) FROM tblDoc WHERE (Auftragsnummer=“ & ValAuftragsnummer +")")
If intCount = 0 Then

strDocNrNeu = mavGetSQLValue(„SELECT isnull(MAX(DocID)+1,1) FROM tblDoc“)
strSQL = „Select * from DeineTabelle“
DoCmd.SetWarnings False

currentdb.execute („INSERT INTO tblDoc (DocID, Auftragsnummer) VALUES (“ _

  • strDocNrNeu + „,“ _
  • ValAuftragsnummer + „)“)
    End If
    Me.Refresh
    DoCmd.SetWarnings True
    End Sub

Okay
Ich habe mich nunmal versucht:
dort wo „gibts nicht“ steht muss nun die funktion hin, mit der eine bestimmte Datei kopiert und mit dem Feldinhalt benannt wird. Kannst du mir noch einmal helfen?

Private Sub btn_QS_Blatt_Click()
On Error GoTo Err_QS_Blatt_Click

Dim strPath As String
Dim feld As String
Dim strlink As String

strPath = „C:\Users\Jannis\Desktop“
feld = Forms!form_auftrag!auftrag_nr
strlink = strPath + „“ + feld + „.pdf“

If Dir(strPath + „“ + feld + „.pdf“) = „“ Then
MsgBox „gibts nicht“
Else
FollowHyperlink strlink
End If

Exit_QS_Blatt_Click:
Exit Sub

Err_QS_Blatt_Click:
MsgBox „Zu diesem Bauteil ist kein QS-Blatt hinterlegt!“
Resume Exit_QS_Blatt_Click
End Sub

Private Sub btn_QS_Blatt_Click()
On Error GoTo Err_QS_Blatt_Click

Dim strPath As String
Dim strFeld As String
Dim strlink As String

strPath = „C:\Users\Jannis\Desktop“
strFeld = Cstr(Forms!form_auftrag!auftrag_nr) 'CSTR wenn die auftrag_Nr numerisch ist.
strlink = strPath + „“ + feld + „.pdf“

If Dir(strPath + „“ + strFeld + „.pdf“) = vbnullstring Then
DoCmd.OutputTo acReport, sDocName, acFormatPDF, strLink, False, False, False, acExportQualityPrint
Else
FollowHyperlink strlink
End If

Exit_QS_Blatt_Click:
Exit Sub

Err_QS_Blatt_Click:
MsgBox „Zu diesem Bauteil ist kein QS-Blatt hinterlegt!“
Resume Exit_QS_Blatt_Click
End Sub

Okay danke für den Tipp mit cstr.
Und auch für den anderen Teil.
Aber ich muss nun doch noch festlegen von wo die Datei kopiert werden soll und wohin oder? Und wie sie benannt werden soll.

Danke schonmal für alles :smile:

Wohin: ist in strLink enthalten ( „C:\Users\Jannis\Desktop“)
Benannt: ist auch in strLink enthalten (strfeld + ".pdf)

Und von wo er die Datei kopieren soll?

Du erstellst Die Datei ja neu. Was willst Du da kopieren?

Nein es ist eine schon bestehende PDF-Datei.
Also bringt Output to nichts. Leider

Ich öffne Dateien =speichere den Pfad und Namen in einem Modul.
Private Const MAX_PATH = 260

Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As Long
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As Long
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As Long
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As Long
End Type

Private Declare Function GetOpenFileName Lib „comdlg32.dll“ Alias „GetOpenFileNameA“ (pOpenfilename As OPENFILENAME) As Long
Private Declare Function GetSaveFileName Lib „comdlg32.dll“ Alias „GetSaveFileNameA“ (pOpenfilename As OPENFILENAME) As Long

'Private Const OFN_READONLY = &H1
'Private Const OFN_OVERWRITEPROMPT = &H2
'Private Const OFN_HIDEREADONLY = &H4
'Private Const OFN_NOCHANGEDIR = &H8
'Private Const OFN_SHOWHELP = &H10
'Private Const OFN_ENABLEHOOK = &H20
'Private Const OFN_ENABLETEMPLATE = &H40
'Private Const OFN_ENABLETEMPLATEHANDLE = &H80
'Private Const OFN_NOVALIDATE = &H100
'Private Const OFN_ALLOWMULTISELECT = &H200
'Private Const OFN_EXTENSIONDIFFERENT = &H400
Private Const OFN_PATHMUSTEXIST = &H800
Private Const OFN_FILEMUSTEXIST = &H1000
'Private Const OFN_CREATEPROMPT = &H2000
'Private Const OFN_SHAREAWARE = &H4000
'Private Const OFN_NOREADONLYRETURN = &H8000
'Private Const OFN_NOTESTFILECREATE = &H10000
'Private Const OFN_NONETWORKBUTTON = &H20000
'Private Const OFN_NOLONGNAMES = &H40000
Private Const OFN_EXPLORER = &H80000
'Private Const OFN_NODEREFERENCELINKS = &H100000
'Private Const OFN_LONGNAMES = &H200000

'Private Const OFN_SHAREFALLTHROUGH = 2
'Private Const OFN_SHARENOWARN = 1
'Private Const OFN_SHAREWARN = 0

Public Function OpenFile(Optional filterstring As String, Optional verzeichnis As String) As String
Dim pOpenfilename As OPENFILENAME
Dim filename$, initDir$, Filter$
Dim L As Long

filename$ = Chr$(0) + Space(MAX_PATH)

If IsMissing(filterstring) Then
Filter$ = „Alle Dateien (*.*)|*.*“
Else
Filter$ = filterstring
End If
If IsMissing(verzeichnis) Then
initDir$ = CurDir
Else
initDir$ = verzeichnis
End If

If Right(Filter, 1) „|“ Then Filter = Filter & „|“
For L = 1 To Len(Filter)
If Mid(Filter, L, 1) = „|“ Then Mid(Filter, L, 1) = Chr$(0)
Next L
Filter = Filter & Chr$(0) & Chr$(0)

With pOpenfilename
.lStructSize = Len(pOpenfilename)
.hwndOwner = Screen.ActiveForm.Hwnd
.lpstrFile = filename
.nMaxFile = MAX_PATH
.lpstrFilter = Filter
.nFilterIndex = 1
.lpstrInitialDir = initDir
.flags = OFN_EXPLORER Or OFN_PATHMUSTEXIST Or OFN_FILEMUSTEXIST
End With
If GetOpenFileName(pOpenfilename) 0 Then
filename = pOpenfilename.lpstrFile
OpenFile = Left(filename, InStr(filename, Chr$(0)) - 1)
Else
OpenFile = vbNullString
End If

End Function

Angestossen wird die Funktion von Me.DocPfad.Value = Dialog.OpenFile(, GetMyDocumentsDir())

Dein „MsgBox „gibts nicht““ ist dann also strPath=DialogOpenfile(), und den Inhalt von strPath speicherst Du ab.

Wahnsinn. Sieht Mega kompliziert aus.
Geht das auch anders? Mit copyfile oder so ähnlich?

Hallo!
Ich weiss nur den Weg.

Martin

Sorry,

zeitbedingt kann ich leider derzeit nicht helfen.
Bitte um Verständnis.

Grüße