Cut & Past .pdf file from a folder to one another in Microsoft Access (1 Viewer)

Alhakeem1977

Registered User.
Local time
Today, 21:08
Joined
Jun 24, 2017
Messages
308
Hi,

How can I achive a Microsoft Access db that can cut a .pdf file from one folder to one another and rename it by selecting the file from a listbox to another listbox within a form called frmFileManager ?

CUT From folder path B:\FOR REVIEW
File name is variable as:
16JUN19-DDB-001.pdf


PAST TO folder path B:\COMPLETED
File name will be renamed as:
16JUN19-DDB-001DONE.pdf

Any suggestions how to build a VBA to achieve this action?

Thanks in advance!


Sent from my HUAWEI NXT-L29 using Tapatalk
 

CJ_London

Super Moderator
Staff member
Local time
Today, 18:08
Joined
Feb 19, 2013
Messages
16,553
use the filecopy and kill functions

Code:
filecopy B:\FOR REVIEW\16JUN19-DDB-001.pdf, B:\COMPLETED\16JUN19-DDB-001DONE.pdf
kill  B:\FOR REVIEW\16JUN19-DDB-001.pdf
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:08
Joined
Oct 29, 2018
Messages
21,358
Hi. I think you can also use the NAME AS statement to "move" a file and rename it at the same time. Cheers!
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 13:08
Joined
Feb 28, 2001
Messages
26,999
First, it is possible for you to rename a file from one path to another path on the same drive (which appears to apply to the case you posted).

The following is AIR CODE in that it only is meant to demonstrate a principle. This means I am not even going to bother to DIM anything.

Code:
SrcFldr = "B:\FOR REVIEW\"
SrcFile = "16JUN19-DDB-001.PDF"
DstFldr = "B:\COMPLETED\"
DstFile = "16JUN19-DDB-001DONE.PDF"
SrcSpec = SrcFldr & SrcFile
DstSpec = DstFldr & DstFile
Name SrcSpec As DstSpec

How you go about filling in the file name and folder for each of the components is up to you, but I broke it down into parts just so you could see how to combine the parts once you have them all.

Note also that this only works as you requested if the source and destination are on the same drive. If this crosses physical drives, you need other syntax.

There is also the idea that you could use a File System Object, which would give you access to a whole range of file operations.

https://docs.microsoft.com/en-us/of...e/user-interface-help/filesystemobject-object

The available methods are listed in the linked article. These methods include file copy, file delete, file rename, and a few other useful abilities.

For simplicity, the original "Name As" will work but is limited. For generality, use the File System Object to do full file manipulation.
 

Alhakeem1977

Registered User.
Local time
Today, 21:08
Joined
Jun 24, 2017
Messages
308
use the filecopy and kill functions



Code:
filecopy B:\FOR REVIEW\16JUN19-DDB-001.pdf, B:\COMPLETED\16JUN19-DDB-001DONE.pdf

kill  B:\FOR REVIEW\16JUN19-DDB-001.pdf
I would like to select the file from a list box (ListSource) within the form, the file could be with a variable date then move it to another list box (ListTarget) and rename the file let say to add Done to it in the same form but the action will take place in the folder as I stated earlier in my post.

I don't know if it's clear to all of you experts, it's very simple I guess for all of you but it's a bit hard for me to build the code.

Thanks all for your responses.

Sent from my HUAWEI NXT-L29 using Tapatalk
 

CJ_London

Super Moderator
Staff member
Local time
Today, 18:08
Joined
Feb 19, 2013
Messages
16,553
not clear to me what you are trying to do. listboxes have nothing to do with files. How are you populating the listboxes?
 

Alhakeem1977

Registered User.
Local time
Today, 21:08
Joined
Jun 24, 2017
Messages
308
not clear to me what you are trying to do. listboxes have nothing to do with files. How are you populating the listboxes?
I mean listbox will show me exactly the contents of the source folder and in the other listbox will show me the contents of the Target folder when select one file or more from Source then press a button between them will move the file to the Target listbox (Target folder).

Sent from my HUAWEI NXT-L29 using Tapatalk
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 13:08
Joined
Feb 28, 2001
Messages
26,999
Your best bet to populate the listbox is to use a FileSystemObject to find all of the eligible files, drop the file spec into a table, and then open up the list box from that table. Since you would have had to use a FileSystemObject to grab this list, you might as well use the other features of the same object to perform file control, copy, rename, and delete operations.
 

Users who are viewing this thread

Top Bottom