Create Folder and copy in it (1 Viewer)

cmatni

Registered User.
Local time
Today, 07:20
Joined
Dec 11, 2006
Messages
19
Hello,

i need to copy files from a folder into another one ?

But what it would be great is if i can make a browser where the user can choose the destination of copying the files ? but if there is any code where i could create a folder , name it and copy files into that folder ?

Thanks guys
 

freakazeud

AWF VIP
Local time
Today, 11:20
Joined
Sep 10, 2005
Messages
221
re:

Hi,
you can use the FileSystem Object to achieve all the file/directory/folder manipulation. To create a folder you can use its CreateFolder method. Access also has an internal MkDir method which works similarly.
For the browsing part check this API Call.
HTH
Good luck
 

cmatni

Registered User.
Local time
Today, 07:20
Joined
Dec 11, 2006
Messages
19
File system object

Thank you for your reply,

since i am new to this kind of code, how exactly i could find help, all i need is to copy files from a folder or path and put them into another path, if you know the code i would be thankful
 

KeithG

AWF VIP
Local time
Today, 07:20
Joined
Mar 23, 2006
Messages
2,592
If you just want to copy a file from one folder to another you can use the FileCopy funciton

FileCopy("CurrentPath","NewPath")
 

cmatni

Registered User.
Local time
Today, 07:20
Joined
Dec 11, 2006
Messages
19
Thank you

Thank you, copying file worked just fine, i am just wondering can i create a folder from vb codes ?? anyone knows how ?? thanks
 

boblarson

Smeghead
Local time
Today, 07:20
Joined
Jan 12, 2001
Messages
32,059
From the help file
MkDir Statement Example
This example uses the MkDir statement to create a directory or folder. If the drive is not specified, the new directory or folder is created on the current drive.

MkDir "MYDIR" ' Make new directory or folder.
 

freakazeud

AWF VIP
Local time
Today, 11:20
Joined
Sep 10, 2005
Messages
221
re:

I already gave you two possible ways to create a folder. Check my initial reply again.
HTH
Good luck
 

Colby

New member
Local time
Today, 09:20
Joined
Dec 13, 2005
Messages
105
one more piece...

does the mkdir function have the ability to see a folder exists and
if not create or if it does then use it?
I have loop that will spit files into a folder named by a var in the loop;
if the folder does not exist it bombs.
This is what I have...


Private Sub cmdExport_all_Click()
Dim sSQL As String
Dim super As String
Dim rcSet As DAO.Recordset
Dim rsTbl As DAO.Recordset
Dim db As DAO.Database


'lets get the supervisor name(s)
sSQL = "SELECT DISTINCT [Supervisor] FROM Commission WHERE IsNull([Supervisor]) = False ORDER BY [Supervisor] "
Set db = CurrentDb()
Set rcSet = db.OpenRecordset(sSQL)
rcSet.MoveLast
rcSet.MoveFirst
Do Until rcSet.EOF
DoCmd.OpenReport "Commissions", acViewPreview, , , acHidden
super = rcSet.Fields(0).Value
Reports![Commissions].Filter = "[Supervisor] = '" & super & "'"
Reports![Commissions].FilterOn = True

DoEvents 'just to put the system on hold to complete the update and other stuff

DoCmd.OutputTo acOutputReport, "Commissions", acFormatSNP, "C:\" & super & \"1.snp"
rcSet.MoveNext
Loop

DoCmd.Close acReport, "Commissions", acSaveYes

Exit Sub
End Sub


is there a way to - before the output cmd to see if the super folder exists and if not create it?

Thanks for your help.
 

boblarson

Smeghead
Local time
Today, 07:20
Joined
Jan 12, 2001
Messages
32,059
You can use the DIR() function to find out if the folder already exists. Check out the additional info on it in the Access VBA help file.
 

freakazeud

AWF VIP
Local time
Today, 11:20
Joined
Sep 10, 2005
Messages
221
re:

No...it will only make a directory within an existing directory...or the top one if there is no top directory.
To check if a directory exists you can use the FileSystem objects FolderExists Method or even easier the Dir() function e.g.:

If Len(Dir("c:\YourDirectory", vbDirectory)) = 0 Then
'doesn't exist so make it
MkDir "c:\YourDirectory"
End If

HTH
Good luck
 

Colby

New member
Local time
Today, 09:20
Joined
Dec 13, 2005
Messages
105
thanks bob and freak, I will dig in and let you know what I come up with.
 

Colby

New member
Local time
Today, 09:20
Joined
Dec 13, 2005
Messages
105
Thanks guys, it worked perfectly.
Now if only I could set up permissions thru access :eek:
 

Users who are viewing this thread

Top Bottom