--- bill purta <[EMAIL PROTECTED]> wrote:
> I looked at several examples for this command on the
> internet but none were written for what I am trying
> to using Access 2003. I was hoping that someone in
> this group had a good example that gets me much
> closer.
>
Okay I did a quick Google search for "VBA Rename
Folder" and came up with numerous results. Here's one
if it is not exactly what you are looking for it
should at least put you on the right path...
*****************< BEGIN >********************
Tip #31:How to rename a File, Folder or Directory from
MS Access
Provided by: Troy Munford, Systems Analyst
Did you know there is a built-in statement for VBA
that allows you to do this without using API calls and
without referencing the File System?
>From the MS Access Help File:
The Name statement moves the file to the new directory
or folder and renames the file, if necessary.
Syntax:
Name oldpathname As newpathname
Name can move a file across drives, but it can only
rename an existing directory or folder when both
oldpathname and newpathname are located on the same
drive. Name cannot create a new file, directory, or
folder.
If oldpathname and newpathname have different paths,
and the same file name, the Name statement moves the
file to the new location and leaves the file name
unchanged.
Using Name, you can move a file from one directory or
folder to another, but you cannot move a directory or
folder.
Using Name on an open file produces an error. You must
close an open file before renaming it. Name arguments
cannot include multiple-character (*) and
single-character (?) wildcards.
Note: Our example below only provides support for
files or simple folder renaming (e.g. the path folder
does not exist). Renaming a directory to a name that
already exists is much more involved and may be
included in a future tip.
Public Function TestNameStatement()
Dim fOK As Boolean
'Folders must exist for Source, do not need to
'exist for destination
fOK = RenameFileOrDir("C:\TestFolder\test.txt", _
"C:\TestFolder\test_NEWNAME.txt")
fok = RenameFileOrDir("C:\TestFolder\test.txt", _
"D:\TestFolder\test_NEWNAME.txt")
'Folder must exist for source.
fok = RenameFileOrDir("C:\TestFolder",
"C:\TestFolder_NEWNAME")
'Folders only will fail across drives.
fok = RenameFileOrDir("C:\TestFolder",
"D:\TestFolder")
End Function
Public Function RenameFileOrDir( _
ByVal strSource As String, _
ByVal strTarget As String, _
Optional fOverwriteTarget As Boolean = False) As
Boolean
On Error GoTo PROC_ERR
Dim fRenameOK As Boolean
Dim fRemoveTarget As Boolean
Dim strFirstDrive As String
Dim strSecondDrive As String
Dim fOK As Boolean
If Not ( _
(Len(strSource) = 0) Or _
(Len(strTarget) = 0) Or _
(Not (FileOrDirExists(strSource)))) Then
'Check if the target exists
If FileOrDirExists(strTarget) Then
If fOverwriteTarget Then
fRemoveTarget = True
Else
If vbYes = MsgBox("Do you wish to overwrite
the " & _
"target file?", _
vbExclamation + vbYesNo, "Overwrite
confirmation") Then
fRemoveTarget = True
End If
End If
If fRemoveTarget Then
'Check that it's not a directory
If ((VBA.GetAttr(strTarget) And _
VBA.vbDirectory)) <> VBA.vbDirectory Then
Kill strTarget
fRenameOK = True
Else
MsgBox "Cannot overwrite a directory",
vbOKOnly, _
"Cannot perform operation"
'FUTURE CODE FOR DIRECTORIES
End If
End If
Else
'The target does not exist
'Check if source is a directory
If ((VBA.GetAttr(strSource) And _
VBA.vbDirectory) = VBA.vbDirectory) Then
'Source is a directory, see if drives are the
same
strFirstDrive = Left(strSource,
InStr(strSource, ":\"))
strSecondDrive = Left(strTarget,
InStr(strTarget, ":\"))
If strFirstDrive = strSecondDrive Then
fRenameOK = True
Else
MsgBox "Cannot rename directories across
drives", _
vbOKOnly, "Cannot perform operation"
'FUTURE CODE FOR DIRECTORIES ON DIFFERENT
DRIVES
End If
Else
'It's a file, ok to proceed
fRenameOK = True
End If
End If
If fRenameOK Then
Name strSource As strTarget
fOK = True
End If
End If
RenameFileOrDir = fOK
PROC_EXIT:
'
Exit Function
'
PROC_ERR:
MsgBox "Error: " & Err.Number & ". " &
Err.Description, , _
"RenameFileOrDir"
Resume PROC_EXIT
End Function
Public Function FileOrDirExists(strDest As String) As
Boolean
Dim intLen As Integer
Dim fReturn As Boolean
fReturn = False
If strDest <> vbNullString Then
On Error Resume Next
intLen = Len(Dir$(strDest, vbDirectory +
vbNormal))
On Error GoTo PROC_ERR
fReturn = (Not Err And intLen > 0)
End If
PROC_EXIT:
FileOrDirExists= fReturn
Exit Function
PROC_ERR:
MsgBox "Error: " & Err.Number & ". " &
Err.Description, , _
"FileOrDirExists"
Resume PROC_EXIT
End Function
*****************< END >********************
__________________________________
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com
------------------------ Yahoo! Groups Sponsor --------------------~-->
Most low income households are not online. Help bridge the digital divide today!
http://us.click.yahoo.com/cd_AJB/QnQLAA/TtwFAA/q7folB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AccessVBACentral/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/