filesystemobject type mismatch error?

G

Guest

Hi,

I'm trying test whether a folder exists using a filesystem object (never
used this before - starting simple but I do need to do more compex stuff).
I've set the FSO in one module using >

Set fs = CreateObject("Scripting.FileSystemObject")

and I'm using >

If fs.FolderExists("C:\Files") Then
MsgBox "Folder Exists!"
End If

In another module to detect whether the specified folder exists. When I run
this I get a type mismatch. I've tried using get folder and trapping the
error but I get the same error. Any ideas why?

Thanks in advance,

Chris
 
G

Guest

I thought it looked correct as per the documentation, the first bit of code
is >

Private Sub Form_Current()
'create a filesystem object
Set fs = CreateObject("Scripting.FileSystemObject")
End Sub

and is attached to the form that opens when the dbase opens. The rest of the
code is (this is on a different form btw) >

Private Sub cmdSaveIdea_Click()
'Dim chk_folder
'Dim fsO As New FileSystemObject
On Error GoTo Err_cmdSaveIdea_Click

If (title.Value <> "") & (date_opened.Value <> "") & (listUser <> "") &
(overview <> "") Then
Me.idea_id.Value = Forms.frmIdea_2.idea_id.Value
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
saved = True
'check to see if directory structure exists. create if not present
If fs.FolderExists("C:\Files") Then
MsgBox "Folder Exists!"
End If
Else
MsgBox ("Please complete the form")
End If


Exit_cmdSaveIdea_Click:
Exit Sub

Err_cmdSaveIdea_Click:
MsgBox Err.description
Resume Exit_cmdSaveIdea_Click

End Sub

Cheers,

Chris
 
G

Guest

This line can cause you problem
Me.idea_id.Value = Forms.frmIdea_2.idea_id.Value
What is the value of Forms.frmIdea_2.idea_id.Value? Are you sure it returns
ay value, And is the value returned is from the same field type.

Also what is "saved = True" Where did you declare the word Saved, and what
type

When you get the error message press ctrl+Break, you will be in the error
capture
Type this

Err_cmdSaveIdea_Click:
MsgBox Err.description
Resume Exit_cmdSaveIdea_Click
Resume

Move the code to the resume, it will move you to the line where the error
is, tell us in which line do you get the error
 
G

Guest

That error was a red herring - the line causing the type mis-match was
If (title.Value <> "") & (date_opened.Value <> "") & (listUser <> "") &
(overview <> "") Then
- I should have used null rather than "" for listUser since it's a list box.
I've got something to work by declaring the filesystem object locally using >

Dim FsO As New FileSystemObject

This is not ideal but I get an error of "object required" if I declare it
using >

Set fs = CreateObject("Scripting.FileSystemObject")

AFAIK this should decalare an object with project level scope which is what
I really need. Any ideas on tis would be appreciated.

Ta for your help,
Chris
 
M

MikeB

Chris_h said:
That error was a red herring - the line causing the type mis-match was
- I should have used null rather than "" for listUser since it's a list box.
I've got something to work by declaring the filesystem object locally using >

Dim FsO As New FileSystemObject

This is not ideal but I get an error of "object required" if I declare it
using >

You have dimmed the fs on one form which has scope to that form only. If you
are going to use it in multiple scopes, you are going to have to dim it Public
or pass it / refer to it byRef from the orginating scope.
 
G

Guest

Thanks, I figured it out myself eventually - I've only been using vB for a
week or so & I'm a bit hazy on some bits!

Chris
 

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