473,406 Members | 2,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Trying to combine two pdf using access vba...

the bottom code is working.... Hard coded the document names

Expand|Select|Wrap|Line Numbers
  1.  
  2. Sub CombinePDFs()
  3.  
  4.     Dim AcroApp As Acrobat.CAcroApp
  5.  
  6.     Dim Part1Document As Acrobat.CAcroPDDoc
  7.     Dim Part2Document As Acrobat.CAcroPDDoc
  8.  
  9.     Dim numPages As Integer
  10.  
  11.     Set AcroApp = CreateObject("AcroExch.App")
  12.  
  13.     Set Part1Document = CreateObject("AcroExch.PDDoc")
  14.     Set Part2Document = CreateObject("AcroExch.PDDoc")
  15.  
  16.     Part1Document.Open ("H:\My Documents\PDF\20161012 Muscat 8601539 COMM(SFSS)EXTRA TAX.pdf")
  17.     Part2Document.Open ("H:\My Documents\PDF\8601539.pdf")
  18.  
  19.     ' Insert the pages of Part2 after the end of Part1
  20.     numPages = Part1Document.GetNumPages()
  21.  
  22.     If Part1Document.InsertPages(numPages - 1, Part2Document, 0, Part2Document.GetNumPages(), True) = False Then
  23.         MsgBox "Cannot insert pages"
  24.     End If
  25.  
  26.     If Part1Document.Save(PDSaveFull, "H:\My Documents\20161012 Muscat 8601539 COMM(SFSS)EXTRA TAX.pdf") = False Then
  27.         MsgBox "Cannot save the modified document"
  28.     End If
  29.  
  30.     Part1Document.Close
  31.     Part2Document.Close
  32.  
  33.     AcroApp.Exit
  34.     Set AcroApp = Nothing
  35.     Set Part1Document = Nothing
  36.     Set Part2Document = Nothing
  37.  
  38.     MsgBox "Done"
  39.  
  40. End Sub
  41.  
the bottom code is NOT working....did not Hard coded the document names.
Expand|Select|Wrap|Line Numbers
  1.  
  2. Function CombinePDFs()
  3.     Dim AcroApp As Acrobat.CAcroApp
  4.  
  5.  
  6.     Dim Part1Document As Acrobat.CAcroPDDoc
  7.     Dim Part2Document As Acrobat.CAcroPDDoc
  8.  
  9.     Dim numPages As Integer
  10.  
  11.     Set AcroApp = CreateObject("AcroExch.App")
  12.  
  13.     Set Part1Document = CreateObject("AcroExch.PDDoc")
  14.     Set Part2Document = CreateObject("AcroExch.PDDoc")
  15.  
  16.     Part1Document.Open ("H:\My Documents\PDF\" & Format(Date, "yyyymmdd") & _
  17.                         " " & [Forms]![frmForCalculations]![sFrmForCalculations].[Form]![LastName] & _
  18.                         " " & [Forms]![frmForCalculations]![sFrmForCalculations].[Form]![Snumber] & _
  19.                         " COMM (SFSS) EXTRA TAX.pdf")
  20.  
  21.     Part2Document.Open ("H:\My Documents\PDF\" & [Forms]![frmForCalculations]![sFrmForCalculations].[Form]![Snumber] & ".pdf")
  22.  
  23.  
  24.     ' Insert the pages of Part2 after the end of Part1
  25.     numPages = Part1Document.GetNumPages()
  26.  
  27.     If Part1Document.InsertPages(numPages - 1, Part2Document, 0, Part2Document.GetNumPages(), True) = False Then
  28.         MsgBox "Cannot insert pages"
  29.     End If
  30.  
  31.     If Part1Document.Save(PDSaveFull, "H:\My Documents\PDF\" & Format(Date, "yyyymmdd") & _
  32.                         " " & [Forms]![frmForCalculations]![sFrmForCalculations].[Form]![Snumber] &  ".pdf") = False Then
  33.         MsgBox "Cannot save the modified document"
  34.     End If
  35.  
  36.     Part1Document.Close
  37.     Part2Document.Close
  38.  
  39.     AcroApp.Exit
  40.     Set AcroApp = Nothing
  41.     Set Part1Document = Nothing
  42.     Set Part2Document = Nothing
  43.  
  44.     MsgBox "Done"
  45. End Function
  46.  

What could I be doing wrong?
Oct 12 '16 #1

✓ answered by jforbes

Are you getting an error?

I would also debug and print out the filenames and then copy and paste them into Windows Explorer to make sure the files and file path exits.

2 2133
jforbes
1,107 Expert 1GB
Are you getting an error?

I would also debug and print out the filenames and then copy and paste them into Windows Explorer to make sure the files and file path exits.
Oct 12 '16 #2
Got it....

an unintentional space was the problem

" .pdf" instead of ".pdf" caused the problem.
Oct 13 '16 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: JED | last post by:
I have an opportunity to work on a web based project using Access. However, there has been a suggestion that MySQL might be a better alternative. The project is actually a small project (less than...
0
by: Paradigm | last post by:
I am using Access 2K as a front end to MySQL running on a Linux server. I am having trouble connectiong to the server. MySQL control centre connects and I can connect using a DSN data source. But...
3
by: bill mahoney | last post by:
Hello, I am using access 2000 and I am trying to email a csv file. I have only used the docmd.sendobject command but you can only email objects that are within the access database ( as far as I...
4
by: Larry Rekow | last post by:
Using Access 2000, I have a linked table using specification named "Test Link Specification" When attempting to create data adapter in VS.Net, it first complains that it cannot retrieve the...
4
by: Mary McRae | last post by:
I'm creating a small test application where I simply take the contents of an Access database and write it to an XML file (using Access' default XML). Once the file is written, I then run it through...
4
by: Bugs | last post by:
Hi everyone. I am trying to open a database which works fine using Access 2003, but when trying to open it on another PC that has Access 2002 I get the following error "This database is...
1
by: konradson | last post by:
Hello, I've built a DB I would like to use in an Intranet through web, this way a small group of people can gain access by typing the address in their browser. It is a small DB, with a few...
3
by: Bruce | last post by:
I have a number of Access 2000 format databases on a Windows 2003 server. For some reason I can no longer compact these databases directly on the server using Access 2003. Access 2000 seems to...
2
by: nabil elraie | last post by:
Am trying to create a POS system for a restaurant using access... and am facing problem on how to : first you know how POS systems work... when i use touch screen and choose the items or food photo...
1
by: slim92 | last post by:
hi guys i am trying to print many pdf files with just click command using access is it possible find my code bellow is not working please any guidance would be much appreciated Option Compare...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.