Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 08-08-2019, 01:52 AM   #1
Rob_Jones101
Newly Registered User
 
Join Date: Aug 2019
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Rob_Jones101 is on a distinguished road
Angry Create a new folder and copy another folders contents into the new folder

I am creating a new database for where I work. It is creating quotes for jobs. When I click the save button its save the quote and opens a new folder which gets its name from three fields on the form. I want it to import or copy files from another folder in the directory to the newly created folder.

I have tried to use the copyfolder function and it does copy the files but to the main folder where all the quotes are held and not into the newly created folder.

On Error GoTo btnOK_Click_Error

Const strParent = "C:\Users\r.jones\Desktop\Quotes\ "
Dim Strquotenumber As String
Dim Strsite As String
Dim StrprojDesc As String
Dim strFolder As String
Dim Strspace As String

Strspace = Space(1) & "- "

Strquotenumber = Me.QuoteNumber
Strsite = Me.Txtsite
StrprojDesc = Me.Project_Description

strFolder = strParent & Strquotenumber & Strspace & Strsite & Strspace & StrprojDesc
If Dir(strFolder, vbDirectory) = "" Then MkDir strFolder


Shell "explorer.exe " & strFolder, vbNormalFocus

If Me.Dirty Then DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "Frmquotebook"
btnOK_Click_Exit: Exit Sub

btnOK_Click_Error: MsgBox "Error" & " In Attempting To Create New Folder. All Fields Must Be Filled In." & vbCrLf_ Cancel = True Resume btnOK_Click_Exit

Is it possible to do this as I have not been able to find anything on it.

Thanks for the help.

Rob_Jones101 is offline   Reply With Quote
Old 08-08-2019, 02:03 AM   #2
Gasman
Enthusiastic Amateur
 
Gasman's Avatar
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 4,332
Thanks: 432
Thanked 790 Times in 766 Posts
Gasman is a jewel in the rough Gasman is a jewel in the rough Gasman is a jewel in the rough
Re: Create a new folder and copy another folders contents into the new folder

CopyFolder requires a source and destination, so how can you not copy into the correct folder.?

https://analystcave.com/vba-filesyst...ba-copyfolder/
__________________
Access novice. Sometimes trying to give something back.
Access 2007

Please, please use code tag # when posting code snippets

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is offline   Reply With Quote
Old 08-08-2019, 02:06 AM   #3
Rob_Jones101
Newly Registered User
 
Join Date: Aug 2019
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Rob_Jones101 is on a distinguished road
Re: Create a new folder and copy another folders contents into the new folder

I want to create a folder and copy files from another folder at the same time. I cant seem to figure out how to create and folder and copy at the same time. I can put another button on the form to copy the files but would prefer it all in one button.

Rob_Jones101 is offline   Reply With Quote
Old 08-08-2019, 02:12 AM   #4
Gasman
Enthusiastic Amateur
 
Gasman's Avatar
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 4,332
Thanks: 432
Thanked 790 Times in 766 Posts
Gasman is a jewel in the rough Gasman is a jewel in the rough Gasman is a jewel in the rough
Re: Create a new folder and copy another folders contents into the new folder

So you create the folder first, then use that as the destination?, which likely should be
Code:
strFolder & "\"
You might not even need the "" ?, I've not used the function, but that link infers that you should.?

HTH
__________________
Access novice. Sometimes trying to give something back.
Access 2007

Please, please use code tag # when posting code snippets

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by Gasman; 08-08-2019 at 02:14 AM. Reason: Site removes \ if not in code tags
Gasman is offline   Reply With Quote
Old 08-08-2019, 02:16 AM   #5
Rob_Jones101
Newly Registered User
 
Join Date: Aug 2019
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Rob_Jones101 is on a distinguished road
Thumbs up Re: Create a new folder and copy another folders contents into the new folder

Thanks Gasman

What would I need to add to the code to get it to copy the files. I understand what you are saying but im quite new to this.

Thanks
Rob_Jones101 is offline   Reply With Quote
Old 08-08-2019, 02:24 AM   #6
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,568
Thanks: 68
Thanked 2,744 Times in 2,629 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: Create a new folder and copy another folders contents into the new folder

after creating the new folder, move the files there.
are the files in "C:\Users\r.jones\Desktop\Quotes\ "?
if so:
Code:
…
…
…
Strspace = Space(1) & "- "

Strquotenumber = Me.QuoteNumber
Strsite = Me.Txtsite
StrprojDesc = Me.Project_Description

strFolder = strParent & Strquotenumber & Strspace & Strsite & Strspace & StrprojDesc
If Dir(strFolder, vbDirectory) = "" Then MkDir strFolder
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object

Set objFSO = CreateObject("Scripting.FilesystemObject")
Set objFolder = objFSO.GetFolder(strParent)
For Each objFile In objFolder.Files
    objFSO.MoveFile objFile.Path, strFolder & "\"
Next

Shell "explorer.exe " & strFolder, vbNormalFocus
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 08-08-2019, 02:33 AM   #7
Gasman
Enthusiastic Amateur
 
Gasman's Avatar
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 4,332
Thanks: 432
Thanked 790 Times in 766 Posts
Gasman is a jewel in the rough Gasman is a jewel in the rough Gasman is a jewel in the rough
Re: Create a new folder and copy another folders contents into the new folder

Quote:
Originally Posted by Rob_Jones101 View Post
Thanks Gasman

What would I need to add to the code to get it to copy the files. I understand what you are saying but im quite new to this.

Thanks
Well presuming your files are in the strParent folder and you want all of them, according to that link it would be along the lines of

Code:
If Dir(strFolder, vbDirectory) = "" Then 
    MkDir strFolder
    fso.CopyFolder strParent & "*" ,strFolder & "\"
End If
where you have declared the fso object at the top of your module with

Code:
Dim fso as Object
Set fso = CreateObject("Scripting.FileSystemObject")
I would add the backslash to the folder name when created and not keep adding it to your name as I have had to do here. Much like you did for the parent.

Review that link I posted. That is what I worked from.

HTH

__________________
Access novice. Sometimes trying to give something back.
Access 2007

Please, please use code tag # when posting code snippets

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is offline   Reply With Quote
The Following User Says Thank You to Gasman For This Useful Post:
Rob_Jones101 (08-08-2019)
Old 08-08-2019, 02:52 AM   #8
Rob_Jones101
Newly Registered User
 
Join Date: Aug 2019
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Rob_Jones101 is on a distinguished road
Smile Re: Create a new folder and copy another folders contents into the new folder

Thanks Gasman

That has worked perfectly. I cant thank you enough.

How would i go about searching for this newly created folder from another form. Or how to create a hyperlink to this folder on creation that can be stored in the table.

Sorry to keep bothering you but I have spent 3 days trying to figure it out and you have just done it in one hour. Thanks
Rob_Jones101 is offline   Reply With Quote
Old 08-08-2019, 03:52 AM   #9
Gasman
Enthusiastic Amateur
 
Gasman's Avatar
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 4,332
Thanks: 432
Thanked 790 Times in 766 Posts
Gasman is a jewel in the rough Gasman is a jewel in the rough Gasman is a jewel in the rough
Re: Create a new folder and copy another folders contents into the new folder

Well it is easy enough to store the path in a table in a hyperlink field and then present that on a form.?

Not used them myself TBH

The experts line Arne might have a better method.?

__________________
Access novice. Sometimes trying to give something back.
Access 2007

Please, please use code tag # when posting code snippets

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is offline   Reply With Quote
Reply

Tags
access , vba access 2016

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
VBScript copy file to folder then cut it and past it in another folder Alhakeem1977 Visual Basic 7 06-24-2019 03:30 AM
Create a Sub-Folder based on the parent folder and record id Danick Forms 16 05-12-2016 01:40 PM
[SOLVED] create folder and sub folders megatronixs Modules & VBA 6 02-16-2015 02:06 AM
Create hyperlinked top level folder names and append new folders to existing list pnvekaria Modules & VBA 0 05-31-2011 06:28 AM
Create Folder and copy in it cmatni Modules & VBA 11 01-22-2007 09:25 AM




All times are GMT -8. The time now is 06:00 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World