Invalid Procedure Call or Arguments

Y

yanto

Hi,
I got this error ("Invalid Procedure Call or Arguments") when run this
code:

'Delete drawing files
Set fs = CreateObject("Scripting.FileSystemObject")
Set fld = fs.GetFolder(pubWorkingDir & "Drawings\")
Set rsc = dbs.OpenRecordset("SELECT * FROM tblDrawings WHERE ID=" &
tempItemID, dbOpenDynaset)
rsc.MoveFirst
Do While Not rsc.EOF
If Dir(pubWorkingDir & "Drawings\" & rsc!DrawingFile) <> "" Then
fld.Files(pubWorkingDir & "Drawings\" & rsc!
DrawingFile).Delete True '(the error caused by this line)
End If
rsc.MoveNext
Loop
rsc.Close
Set rsc = Nothing
Set fld = Nothing
Set fs = Nothing

and the programm stop at this line " fld.Files(pubWorkingDir &
"Drawings\" & rsc!DrawingFile).Delete True " and the error come
out .
Do I miss somthing?
Thanks for any help
Yanto
 
S

Stuart McCall

yanto said:
Hi,
I got this error ("Invalid Procedure Call or Arguments") when run this
code:

'Delete drawing files
Set fs = CreateObject("Scripting.FileSystemObject")
Set fld = fs.GetFolder(pubWorkingDir & "Drawings\")
Set rsc = dbs.OpenRecordset("SELECT * FROM tblDrawings WHERE ID=" &
tempItemID, dbOpenDynaset)
rsc.MoveFirst
Do While Not rsc.EOF
If Dir(pubWorkingDir & "Drawings\" & rsc!DrawingFile) <> "" Then
fld.Files(pubWorkingDir & "Drawings\" & rsc!
DrawingFile).Delete True '(the error caused by this line)
End If
rsc.MoveNext
Loop
rsc.Close
Set rsc = Nothing
Set fld = Nothing
Set fs = Nothing

and the programm stop at this line " fld.Files(pubWorkingDir &
"Drawings\" & rsc!DrawingFile).Delete True " and the error come
out .
Do I miss somthing?
Thanks for any help
Yanto

You don't need to use the FSO for this. The built-in VBA command Kill will
do the job nicely:

Set rsc = dbs.OpenRecordset("SELECT * FROM tblDrawings WHERE ID=" &
tempItemID, dbOpenDynaset)
rsc.MoveFirst
Do While Not rsc.EOF
If Dir(pubWorkingDir & "Drawings\" & rsc!DrawingFile) <> "" Then
Kill pubWorkingDir & "Drawings\" & rsc!DrawingFile
End If
rsc.MoveNext
Loop
 
Y

yanto

You don't need to use the FSO for this. The built-in VBA command Kill will
do the job nicely:

Set rsc = dbs.OpenRecordset("SELECT * FROM tblDrawings WHERE ID=" &
tempItemID, dbOpenDynaset)
rsc.MoveFirst
Do While Not rsc.EOF
If Dir(pubWorkingDir & "Drawings\" & rsc!DrawingFile) <> "" Then
Kill pubWorkingDir & "Drawings\" & rsc!DrawingFile
End If
rsc.MoveNext
Loop- Hide quoted text -

- Show quoted text -

Thanks Stuart, it's worked.
Best Regards
Yanto
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top