I have a form in MS Access which is used to fill in some invoice details. Sometimes, the users will open the invoice to copy over the details. The invoice is always a PDF file. I want to make sure that as soon as the user is done with the form and closes it, the invoice PDF file is closed, too. Is there a way to do this using VBA?
Asked
Active
Viewed 79 times
0
-
Don't need Shell to rename files https://stackoverflow.com/questions/51376612/copy-and-rename-a-file, https://stackoverflow.com/questions/17660117/how-do-i-rename-a-file-using-vbscript#:~:text=1%20Create%20Folder%20Source%20and%20Archive%20in%20D,renamed%20with%20existing%20file%20name%20and%20current%20date – June7 Feb 10 '23 at 02:02
-
@June7, the problem is, the file is open. I need to the code to close it and rename it. – user2395238 Feb 10 '23 at 02:13
-
@June7, the problem is, the file is already open. to use any of the methods you suggest, the file needs to be closed. and I'd like VBA to close it – user2395238 Feb 10 '23 at 02:21
-
Can I close the file that was open in a different way, not by using Shell? How would I reference the file? I need to get the PID number, that is returned when shell open is used. But, the file can be open different way, user might open it by doubleclicking the file. I need to make sure the file is closed when the form is closed. – user2395238 Feb 10 '23 at 02:33
-
@June7, your solution only works if I use shell command to open the file, and that is not my case – user2395238 Feb 10 '23 at 02:34
-
Maybe this will offer a path https://stackoverflow.com/questions/70414105/vba-using-win32-api-showwindow-function-closes-window – June7 Feb 10 '23 at 02:55
-
the files that I am trying to close are PDF files. That seems to be for Word documents – user2395238 Feb 10 '23 at 03:34
-
I am guessing that would require modifying line `WinWnd = FindWindow(vbNullString, "somedocument.docx - Word")`. However, since you and code don't know what file was opened by user, this is moot. Would you want to close all PDF files? – June7 Feb 10 '23 at 03:36
-
1Another SO to review https://stackoverflow.com/questions/27880203/close-an-opened-pdf-after-opening-it-using-followhyperlink – June7 Feb 10 '23 at 04:08
-
yes, closing all PDF files would work – user2395238 Feb 10 '23 at 05:38