Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To 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 April 8th, 2005, 10:41 AM
Authorized User
 
Join Date: Mar 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default check for directory, or create new if not found

I'm using the transferspreadsheet function in VBA (Access 2003) to create .xls files of several queries. I would like these "output" files to be saved to a directory with the path of "C:\IPDC Files". My dilemma is how do I use VBA to check to see if this directory exists first... and if NOT, then go ahead and create it?

Any help is appreciated!!

Rick
__________________
Rick
 
Old April 8th, 2005, 12:18 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Try changing to the directory, and if that generates an error create it.
Code:
' ChDrive Drive As String
' ChDir Path As String

Public Sub DoIt()

    On Error GoTo Er

    Dim PthNotExist As Boolean  ' A Boolean’s initial value = False

    If Left$(CurDir, 2) <> "C:" Then
        ChDrive "C:"
    End If

    ChDir "C:\IPDC Files"       ' If the path does not exist, the error haldler
                                ' will be invoked with error #76.
    If PthNotExist Then         ' This will have been set in the error handler
        MkDir "C:\IPDC Files"
    End If

    PthNotExist = False         ' Re-initialize the value, if it is not going
                                ' to be used to take additional action.
Rs: Exit Sub

Er: If Err.Number = 76 Then     ' Path Not Found
        PthNotExist = True
        Resume Next
    End If

    MsgBox "Error " & Err.Number & ", """ & Err.Description & """"
    Resume Rs

End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT Check if directory exist ArnArn XSLT 3 November 23rd, 2008 03:44 PM
Check to make sure a directory exists stonesbg ASP.NET 2.0 Basics 3 January 18th, 2007 03:25 PM
How to Create new folder(directory) in Srever ? Raam ASP.NET 2.0 Professional 1 May 10th, 2006 12:48 PM
create xsl file in c directory keyvanjan Classic ASP Basics 2 June 21st, 2005 04:52 PM





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