Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.

Reply With Quote
  #2 (permalink)  
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
Reply With Quote
  #3 (permalink)  
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.

Reply With Quote
  #4 (permalink)  
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:40 AM.


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