View Full Version : Path not found error


dan1dyoung
08-07-2007, 04:05 PM
I have tried running the code in two halfs and they both work OK, but together i get the path not found error.

Total Code
Dim strDeleteQuoteRecordMsg As String
strDeleteQuoteRecordMsg = "Are you sure you want to delete this Quote?"

Beep
If MsgBox(strDeleteQuoteRecordMsg, vbYesNo, APP_TITLE) = vbYes Then
DoCmd.SetWarnings False
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.SetWarnings True
Forms!frmQuotesList.lstQuotes.Requery

Dim strDeleteQuoteFolderMsg As String
strDeleteQuoteFolderMsg = "Do you also want to delete the Folder and Files on the server?"

If MsgBox(strDeleteQuoteFolderMsg, vbYesNo, APP_TITLE) = vbYes Then

DeleteDir = "C:\accesstest\" & [Forms]![frmViewQuote]![TotalQuoteNumber]

If Dir(DeleteDir, vbDirectory) <> "" Then

Dim MyObject As Object
Set MyObject = CreateObject("Scripting.FileSystemObject")
MyObject.DeleteFolder DeleteDir, True

Dim strDeleteQuoteFolderSuccessMsg As String
strDeleteQuoteFolderSuccessMsg = "The Folder and Files were deleted!"

MsgBox "strDeleteQuoteFolderSuccessMsg,,APP_TITLE"
DoCmd.Close
Else

Dim strDeleteQuoteFolderEmptyMsg As String
strDeleteQuoteFolderEmptyMsg = "No Folders or Files to delete!"

MsgBox "strDeleteQuoteFolderEmptyMsg,,APP_TITLE"
DoCmd.Close
End If


Else
' Do nothing


End If

One part, works OK
DeleteDir = "C:\accesstest\" & [Forms]![frmViewQuote]![TotalQuoteNumber]

If Dir(DeleteDir, vbDirectory) <> "" Then

other part, works OK
DeleteDir = "C:\accesstest\" & [Forms]![frmViewQuote]![TotalQuoteNumber]

If Dir(DeleteDir, vbDirectory) <> "" Then

Dim MyObject As Object
Set MyObject = CreateObject("Scripting.FileSystemObject")
MyObject.DeleteFolder DeleteDir, True

So no problems with field values in the string?????

Thanks

Dan

Guus2005
08-09-2007, 12:25 AM
Working in a network environment? Try UNC names (\\Server\Path\Dir1\Dir11\Filename.ext)

HTH

dan1dyoung
08-09-2007, 12:28 PM
Hi HTH,

It will be but at present it is local for testing.

It works as it is but not with the If clause aswell as the delete directory.

I have changed it so each part has its own path,

so


DeleteDir1 = "C:\accesstest\" & [Forms]![frmViewQuote]![TotalQuoteNumber]

If Dir(DeleteDir1, vbDirectory) <> "" Then

Dim MyObject As Object
Set MyObject = CreateObject("Scripting.FileSystemObject")
DeleteDir2 = "C:\accesstest\" & [Forms]![frmViewQuote]![TotalQuoteNumber]
MyObject.DeleteFolder DeleteDir2, True

but no luck.

I have also tried declaring it as a string, so:

Dim DeleteDir As String

DeleteDir = "C:\accesstest\" & [Forms]![frmViewQuote]![TotalQuoteNumber]

but still no joy

Thanks

Dan

Guus2005
08-10-2007, 01:27 AM
I hope you are familiair with the immediate window? (ctrl-g)
Put a breakpoint where you get the error message. So just before you get the error message the code is stopped. Then type in the immediate window?DeleteDir1It gives you the contents of the variable. Is this content good? Is this really where your file is?
Do you get the error on the IF statement of the DeleteDir statement?
Why do you use DeleteDir2 if you already have a DeleteDir1 with the same contents?\

dan1dyoung
08-10-2007, 11:06 AM
Not that great with the immediate window, so used MsgBox instead

If MsgBox(strDeleteQuoteFolderMsg, vbYesNo, APP_TITLE) = vbYes Then
MsgBox "1"
DeleteDir = "C:\accesstest\" & [Forms]![frmViewQuote]![TotalQuoteNumber]
MsgBox "2"
If Dir(DeleteDir, vbDirectory) <> "" Then
MsgBox "3"
Dim MyObject As Object
MsgBox "4"
Set MyObject = CreateObject("Scripting.FileSystemObject")
MsgBox "5"
MyObject.DeleteFolder DeleteDir, True
MsgBox "6"


I get the MsgBox dialogs below

1
2
3
4
5
Then File Not Found (Not 6)

I used 2 DeleteDir paths as both the If statement and the DeleteDir statement worked on there own (Commented each part out), but together they failed so wondered if the variable DeleteDir did not like being used twice in the same function.

Thanks

Dan

dan1dyoung
08-10-2007, 03:25 PM
I have put a stop before the code and then used F8 to step through each line.

If i hover over the DeleteDir in "If Dir(DeleteDir, vbDirectory) <> "" Then" then it returns "C:\accesstest" once past MsgBox "1". The same is true on the DeleteDir in "MyObject.DeleteFolder DeleteDir, True". But at that point it jumps to the error handler

I notice the DeleteDir = "C:\accesstest\" & [Forms]![frmViewQuote]![TotalQuoteNumber] = Null????

If MsgBox(strDeleteQuoteFolderMsg, vbYesNo, APP_TITLE) = vbYes Then
MsgBox "1"
DeleteDir = "C:\accesstest\" & [Forms]![frmViewQuote]![TotalQuoteNumber]
MsgBox "2"
If Dir(DeleteDir, vbDirectory) <> "" Then
MsgBox "3"
Dim MyObject As Object
MsgBox "4"
Set MyObject = CreateObject("Scripting.FileSystemObject")
MsgBox "5"
MyObject.DeleteFolder DeleteDir, True
MsgBox "6"

Thanks

Dan

Guus2005
08-13-2007, 03:58 AM
First put all your dim statements at the beginning of the procedure.
Seems that you forgot to dimension DeleteDir. Put Option Explicit at the start of your module:

Option Compare Database
Option Explicit

Compile your code. Run your code.
You probably get an error message invalid use of null.

Guus2005
08-13-2007, 04:05 AM
First put all your dim statements at the beginning of the procedure.
Seems that you forgot to dimension DeleteDir. Put Option Explicit at the start of your module:

Option Compare Database
Option Explicit

Compile your code. Run your code.
You probably get an error message invalid use of null.

dan1dyoung
08-20-2007, 11:06 AM
Guus2005,

Great that worked OK

Final Code:
Private Sub CmdDelete_Click()
On Error GoTo Err_CmdDelete_Click

Me.Form.AllowAdditions = True
Me.Form.AllowDeletions = True
Me.Form.AllowEdits = True
CmdEdit.Enabled = False

Dim DeleteDir As String

Dim strDeleteQuoteRecordMsg As String
Dim strDeleteQuoteFolderMsg As String
Dim strDeleteQuoteFolderSuccessMsg As String
Dim strDeleteQuoteFolderEmptyMsg As String

DeleteDir = "C:\accesstest\" & [Forms]![frmViewQuote]![TotalQuoteNumber]

strDeleteQuoteRecordMsg = "Are you sure you want to delete this Quote?"
strDeleteQuoteFolderMsg = "Do you also want to delete the Folder and Files on the server?"
strDeleteQuoteFolderSuccessMsg = "The Folder and Files were deleted!"
strDeleteQuoteFolderEmptyMsg = "No Folders or Files to delete!"

Beep
If MsgBox(strDeleteQuoteRecordMsg, vbYesNo, APP_TITLE) = vbYes Then
DoCmd.SetWarnings False
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.SetWarnings True
Forms!frmQuotesList.lstQuotes.Requery




If MsgBox(strDeleteQuoteFolderMsg, vbYesNo, APP_TITLE) = vbYes Then

If Dir(DeleteDir, vbDirectory) <> "" Then

Dim MyObject As Object

Set MyObject = CreateObject("Scripting.FileSystemObject")

MyObject.DeleteFolder DeleteDir, True


MsgBox strDeleteQuoteFolderSuccessMsg, , APP_TITLE
DoCmd.Close
Else


MsgBox strDeleteQuoteFolderEmptyMsg, , APP_TITLE
DoCmd.Close
End If


Else
' Do nothing


End If
End If


Exit_CmdDelete_Click:
Exit Sub

Err_CmdDelete_Click:
MsgBox Err.description
Resume Exit_CmdDelete_Click

End Sub

Thanks

Dan