Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
| Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 25th, 2007, 04:19 PM
Authorized User
 
Join Date: Apr 2007
Location: , , .
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default Create folder in file system to place output into

I am exporting an access query as an excel file and would like to create a folder in the Windows file system to put the file into. Currently the file just goes into the user's designated directory path. I would like to create a folder in this directory path, then put the exported file into that.

If I knew how to create the folder I think could handle the rest.

Any ideas on how to make this happen?

Thanks,
Coby.

 
Old June 26th, 2007, 07:39 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Yes. You need to use the Scripting.FileSystemObject.

Dim objFSO As Variant
Dim objFolder As Variant

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder("C:\Sample")

However, if it already exists, you may run into problems. Try:

Dim objFSO As Variant
Dim objFolder As Variant

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists("C:\Sample") Then
   DoCmd.... transfer to this folder
Else
   Set objFolder = objFSO.CreateFolder("C:\Sample")
   DoCmd.... transfer to this folder
End If


If you name the path like this:

Dim sPath As String

sPath = "C:\Documents and Settings\UserName\My Documents\NewFolder"

Then the syntax is this:

Set objFolder = objFSO.CreateFolder(sPath)


Did that help?


mmcdonal
 
Old June 26th, 2007, 10:34 AM
Authorized User
 
Join Date: Apr 2007
Location: , , .
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That worked perfectly! Could you recommend a good reference for info about the Fso (ie, literature or debugging library) where I could find all of the different methods as "CreateObject" as you have used here?

Coby.

 
Old June 26th, 2007, 10:39 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Glad to hear it. Two books I would not be without:

Microsoft Windows 2000 Scripting Guide (yes, 2000. This stuff hasn't changed much)
ISBN: 0735618674

Advanced VBScript for Microsoft Windows Administrators.
ISBN: 2005937886

I would also look for some works on Windows Powershell since it will replace or augment this soon. This functionality should be available for awhile, though.

Sorry Wrox.


mmcdonal




Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a folder/file with a long path eelisMX Pro VB.NET 2002/2003 3 May 30th, 2014 05:02 AM
Place an .ini file on Tomcat 5.5.9 dolortiga Apache Tomcat 0 June 12th, 2005 07:53 PM
creating folder: System.UnauthorizedAccessExceptio akthar General .NET 3 August 27th, 2004 07:58 AM
how to create/use php template file/system junemo Beginning PHP 1 April 23rd, 2004 03:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.