CreateFolder Error

G

Guest

to all,

i haved copied this code from internet and i want to use this on my database
but when i try to run the code it prompt me this error:
Compile Error:
User-defined type not defined

Private Sub cmd_upload_Click()

Dim fso As New FileSystemObject
Dim fldr As Folder
On Error GoTo FolderError
'foldername is the name of the folder you wish to
'create passed by value into this create procedure
Set fldr = fso.CreateFolder(foldername)
Set fldr = Nothing
Set fso = Nothing
Exit Sub
FolderError:
Exit Sub
Resume Next
End Sub

how can i solve this problem?

Resti
 
T

Tom Wickerath

Hi Resti,

You need to include a reference to the "Microsoft Scripting Runtime" library (scrrun.dll). Click
on Tools > References, scroll down the list until you find this item and then place a check in
the box to select it. Click on OK to dismiss the references dialog. Then click on Debug > Compile
DatabaseName.


Tom
_______________________________________


to all,

i haved copied this code from internet and i want to use this on my database
but when i try to run the code it prompt me this error:
Compile Error:
User-defined type not defined

Private Sub cmd_upload_Click()

Dim fso As New FileSystemObject
Dim fldr As Folder
On Error GoTo FolderError
'foldername is the name of the folder you wish to
'create passed by value into this create procedure
Set fldr = fso.CreateFolder(foldername)
Set fldr = Nothing
Set fso = Nothing
Exit Sub
FolderError:
Exit Sub
Resume Next
End Sub

how can i solve this problem?

Resti
 
D

Douglas J. Steele

As an alternative to what Tom suggested, you could use late binding, and not
require any reference be set:

Private Sub cmd_upload_Click()

Dim fso As Object
Dim fldr As Object
On Error GoTo FolderError
'foldername is the name of the folder you wish to
'create passed by value into this create procedure
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.CreateFolder(foldername)
Set fldr = Nothing
Set fso = Nothing
Exit Sub

Of course, VBA has a built-in MkDir statement that will let you create
folders without requiring FSO.
 

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