Results 1 to 10 of 10
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195

    VBA Close Avtive pdf doc

    Hi Guys, is there a method to close and active pdf document, the obvious answer is re maximise and click X but when there are 100 to be opened individually then closed once data is logged, it would be so much easier for me to close it from the last procedure before we need to close to open new one, or even when opening a new one is an option to close an active one



    I have the following but unsure of the correct method

    Code:
    Dim MyFile as String
    MyFile = "T:\Folder1\Folder2\" & me.cboPDF & ".pdf"
    Close MyFile

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    You can only transfer data to/from one at a time, yes? So why not open, transfer, close, loop? The only other idea I have is to use API to get the window handle and close a window based on that, but don't see that as viable with so many open windows, nor necessary - unless there is a reason why you need 100 documents open at the same time. You may generate Access error from having too many open connections.
    EDIT - just re-read your post. Are you saying you want to do just as I suggested but don't know how?

    Lots of posted code in several forums but I don't have any at hand. A search provided these as two of many
    https://www.experts-exchange.com/que...-from-VBA.html
    http://access.mvps.org/access/api/api0025.htm
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi Micron, sorry, only 1 document open at any one time, these are opened from a combo box (1 at a time) , minimised while we add data ,then manually maximised to close before opening a new one, I am having to point the mouse to the minimized pdf on the task bar and move to click x each time, when we have potentially 100 documents to do, much quicker for vba to close, even better to do this before a new one is opened from the combo ie: check if pdf is minimised on the task bar and close if there is one open … hope I have explained better

    Much appreciated

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    You probably noticed our posts are crossing. I presume the links will provide a start for you. I see the combo BeforeUpdate running the code to close the pdf window, then the AfterUpdate opening a new one? Hope the links help as it's not something that I've ever needed to do. Maybe someone else will troll by and provide some ready made code...

  5. #5
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    maybe describe your process a bit better. Are you actually updating the .PDF file itself? or are you doing a bunch of exporting and every time you export a .pdf it opens the window?

    If it's the former can you not just export from your database a 'fresh' .pdf with the updated data?
    if it's the latter there is an option to prevent the .pdf window from opening

    The AUTOSTART option in the .outputto command can be set to FALSE to prevent it from opening.

    .OutputTo (ObjectType, ObjectName, OutputFormat, OutputFile, AutoStart, TemplateFile, Encoding, OutputQuality)



  6. #6
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi rpeare, thank you for your reply, we have pdf files in a folder uploaded by a customer

    current procedure is, select the pdf named ie: 123.pdf
    this opens the pdf and adds a new record to db called 123
    we look at data on pdf to fill more fields in on access db
    so we minimise it to type the data from the minimised pdf
    once we have added the data
    then we open the minimised pdf from task bar to close it
    Done
    But rather than having to maximise a pdf to close manually, i like microns idea, add a close active pdf file called 123.pdf on the before event of the same combo that opens the next one (after update event), hoping this makes sense, so the end result is saving a lot of time if we have to sit and open and close 100 pdf docs individually it would be quicker to close the active pdf (123.pdf) via vba..

    kindest

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Are these pdf forms? That should make it possible to get values from your forms and skip the manual entry. Access vba with pdf form fields is not a common topic but I have seen several examples of it - even in this forum. IIRC, there are threads with solutions, but I have to admit it's not a walk in the park.

    Your new procedure could potentially be
    - loop through folder, get file name and open hidden
    - create your 123 record (a field value that indicates the pdf file name?)
    - grab the form values
    - if no error, write pdf path to table so it can be opened later from Access form
    - close file
    Note that the path came after the table write, meaning if there's a path, data transfer was OK.
    A button starts the file dialog to navigate to pdf folder; no combo for picking files.

  8. #8
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Yeah, I was going to suggest what Micron did. you can parse PDF's to get data out of them, this manual part is for the birds.

  9. #9
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi Guy's, thank you so much for your responses, yes there is a field in the database that is called the file name 123.pdf and 536.pdf and 732.pdf etc etc

    I think rather than me go through a thourough change, another note is that when field entries are added from the pdf, the database fields changes required data as its being added in which i think i would prefer to open file to 1: check we have the data correct: 2 another procedure is the file is renamed via a done button (can be changed to before update of the combo that opens the pdf) file is renamed 123 Added.pdf 3: when the product is shipped (a consignment moves the file is renamed again to 123 shipped 09-08-19.pdf to a backup folder

    So I think with many procedures going on, I love microns idea of before update on the combo that opens the file initially (after update) check if there is a pdf open called (me.cboPDF) which is the file name then if it is, close it and rename it 123.pdf added, the new one opens and the added one closes, obviously cancel event if file not open.. this would be fab

    Thank you both again for your kind replies

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    you're welcome. Hope the search provides some useful code solutions.
    Good luck.

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

Similar Threads

  1. rs.Close
    By thebigthing313 in forum Programming
    Replies: 1
    Last Post: 12-23-2014, 02:00 PM
  2. Replies: 5
    Last Post: 09-01-2014, 12:11 PM
  3. Close Dialog Box instead of Close App
    By ccchan in forum Access
    Replies: 4
    Last Post: 03-19-2014, 08:34 AM
  4. Replies: 4
    Last Post: 01-31-2014, 11:47 AM
  5. Replies: 2
    Last Post: 06-20-2011, 03:10 PM

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