hi there i want to create a directory on the C drive, this code isn't working do you have any ideas
If sBackUp = "" Then
ChDir "C:\"
MkDir "tpbackup"
sBackUp = "C:\tpbackup\bookbkup.mdb"
End If
Rohan West
Printable View
hi there i want to create a directory on the C drive, this code isn't working do you have any ideas
If sBackUp = "" Then
ChDir "C:\"
MkDir "tpbackup"
sBackUp = "C:\tpbackup\bookbkup.mdb"
End If
Rohan West
Try this:
Code:MkDir ("C:\tpbackup")
Code:
'Check if directory exists
'-----------------------------------
Public Function DirExists(ByVal sDirName As String) As Boolean
Dim sDir As String
On Error Resume Next
DirExists = False
sDir = Dir$(sDirName, vbDirectory)
If (Len(sDir) > 0) And (Err = 0) Then
DirExists = True
End If
End Function
Private Sub command1_click()
Dim sBackup As String, sDirectory As String
sBackup = "C:\tpbackup\bookbkup.mdb"
sDirectory = "C:\tpbackup"
'does file exist using fso
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
'if the file exists
If fs.fileexists(sBackup) = True Then
'check to see if directory exist to avoid error
'if not create it
If DirExists(sDirectory) = False Then
MkDir "C:\aatpbackup"
End If
Else
MsgBox "C:\sBackup Does Not Exist...Your code here!"
End If
Set fs = Nothing
End Sub