Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
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 September 30th, 2005, 10:21 AM
Registered User
Join Date: Sep 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Check For Existing Folders & Files

I have some code that creates a folder and copies a file to it, named after user input, I need to be able to use the DIR function to check to see if the directory and file already exist.Any help?

Private Sub Command61_Click()
Dim Number As String
Dim source As String
Dim output As String
Dim output1 As String
Dim output2 As String

source = "e:\2005quotes\test.xlt"

'sets str value from access text box containing user supplied quote #
Number = txtNumber.Text
'names directory

output = "e:\2005quotes\" & Number & "\"
'names file
output1 = output & Number & ".xls"

'creates directory named after quote (user input)
MkDir (output)
'copies template to quotes directory
FileCopy source, output1


Old September 30th, 2005, 11:25 AM
Friend of Wrox
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts

You need to use the FileSystemObject and then name the file, and then do

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("C:\MyFileName.ext") Then
End If

You may have problems with variable declarations in VBA, so do something like this unless you can sort it out better. This is a typeless variable in VBA

"Dim objFSO"

Don't use As etc.


Old September 30th, 2005, 11:43 AM
Registered User
Join Date: Sep 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks, I will try it now.:D

Similar Threads
Thread Thread Starter Forum Replies Last Post
connect to files from different folders lcyean ASP.NET 2.0 Basics 1 May 11th, 2007 07:23 AM
Copy files & Folders application in ASP.net rupakroy5 ASP.NET 1.0 and 1.1 Basics 0 May 8th, 2006 10:45 PM
How to check whether a filie is existing szms VB.NET 2002/2003 Basics 2 December 6th, 2004 03:49 PM
check for existing records b4 insertion deian Access ASP 11 June 13th, 2004 09:01 AM
Check for existing record echajmovic Access 1 November 3rd, 2003 08:03 PM

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