Results 1 to 7 of 7
  1. #1
    rosaj is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2011
    Posts
    7

    Save form as PDF

    Hi,

    I'm using access 2007 and I have over 20 forms that I need to save the current record in form view as a pdf every time a new record is entered. The code shown below saves every record in the record source table in one pdf. So in the one pdf file I have maybe 40 records in form view. The code is called from a button click on the form. I need everything to be done from that one button click. The person that is going to be filling out this form has no idea what access is and needs everything to be as simple as possible. The code is below and I worte in comments to try to explain better:

    Private Sub Save_Click() 'button on form
    On Error GoTo save_record_Click_Err
    On Error Resume Next

    If IsNull(Me.Signature) Then
    MsgBox "Please fill out the Signature field" 'check completed fields
    Cancel = True


    Else

    DoCmd.RunCommand acCmdSaveRecord 'saves as record in table
    If (MacroError <> 0) Then
    Beep
    MsgBox MacroError.Description, vbOKOnly, ""
    End If

    'Brings up the last saved record which would be the one just entered in
    DoCmd.GoToRecord acActiveDataObject, "Form Name", acLast


    'Calls function
    SaveToPDF ("Form Name")

    -------------------------------------------------------
    Public Function SaveToPDF(SrcFile As String)
    On Error GoTo SaveToPDF_Err

    'SrcFile = name of form the function was called from
    'DestPath = Destination path for PDF file
    Dim DestPath As String
    'DestFile = Destination file name for PDF file
    Dim DestFile As String
    'ShowPdf = launch acrobat and display saved PDF file
    Dim ShowPdf As Boolean

    'Saves the file to specific folder(this isn't my real file path)
    DestPath = "\My Documents\Practice Save\"
    'Formats the file name
    DestFile = Month(Now) & "_" & Day(Now) & "_" & Year(Now) & "_" & [Certificate #]

    ShowPdf = False
    Dim strDestFile As String
    strDestFile = DestPath & DestFile & ".pdf"

    Me.Filter = "ID=" & Me.ID
    Me.FilterOn = True
    DoCmd.OutputTo acOutputForm, scrFile, acFormatPDF, strDestFile, False
    Me.FilterOn = False

    SaveToPDF_Exit:
    Exit Function

    SaveToPDF_Err:
    Resume SaveToPDF_Exit

    End Function

    I'm not sure what I'm doing wrong but any help would be appreciated Thanks!!

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    is it generating a file at all? if it is what are the contents of the file, is it blank?

    if the actual path in your code is \My Documents\Practice Save\

    try changing it to

    currentproject.path & "\"

    this will set the pdf location to be the same directory as the database itself.

    have you put in any debug.print breaks to show where your code is breaking down?

  3. #3
    rosaj is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2011
    Posts
    7
    Thanks so much for replying

    It is generating a file and its putting it in the correct location. Say i have 5 records in my table that the form is bound to. In the generated file there are all 5 records in form view saved as that single pdf. So i end up with 5 pages of my form with different record info on it. Am I explaining that correctly? sorry if its confusing.

    I've tried the debug print but nothing comes up in my watch list or in the immediate action window that isn't supposed to happed

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Are you saying you only want to print the current record you're on to a PDF and not the entire data set?

  5. #5
    rosaj is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2011
    Posts
    7
    yes that is exactly right! i'm sorry i wasnt explaining it very well before

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I don't think there is a way to limit it on a form. The easiest thing to do would be to create a simple report that uses the current record's unique key field as the criteria, then when you want to print the screen just have a button click event to print your report.

  7. #7
    rosaj is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2011
    Posts
    7
    oh ok thanks so much for your help

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Can't save or close form
    By Buakaw in forum Forms
    Replies: 4
    Last Post: 07-26-2011, 04:47 AM
  2. Replies: 1
    Last Post: 07-18-2011, 03:08 AM
  3. Replies: 9
    Last Post: 01-20-2011, 02:22 PM
  4. Save and New Form
    By Bakar in forum Forms
    Replies: 1
    Last Post: 12-20-2010, 04:50 AM
  5. Save and Go to another form - simple yes?
    By durstlaw in forum Forms
    Replies: 1
    Last Post: 12-15-2009, 12:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums