FileSystemObject --Type mismatch

  • Thread starter NuBie via AccessMonster.com
  • Start date
N

NuBie via AccessMonster.com

I posted the same thread on Querries section. I don't know how to move it
from that section to this section. Sorry for double post.

Given this declaration i got runtime error: 13 Type Mismatch.
variable origin is a string containg the folder location.

Dim fs As New FileSystemObject
Dim f As Folder
Dim afile As File
Set f = fs.GetFolder(origin)

So.. what's wrong why i get type mismatch?


Thanks
 
S

Stefan Hoffmann

hi,
Given this declaration i got runtime error: 13 Type Mismatch.
variable origin is a string containg the folder location.

Dim fs As New FileSystemObject
Dim f As Folder
Dim afile As File
Set f = fs.GetFolder(origin)
hmm, first of all: don't use the As New syntax.

This works for my using Access 2003 with a reference set to "Microsoft
Scripting Runtime":

Option Compare Database
Option Explicit

Public Sub test()

Dim fs As FileSystemObject
Dim f As Folder
Dim afile As File

Set fs = New FileSystemObject
Set f = fs.GetFolder("C:\Temp")

MsgBox f.Name

End Sub


mfG
--> stefan <--
 
N

NuBie via AccessMonster.com

Dim fs As New FileSystemObject
' replace this line Dim f As Folder with
Dim f As Scripting.Folder
Dim afile As File
Set f = fs.GetFolder(origin)

Thread resolved!!!
someone may find this useful!!
 
N

NuBie via AccessMonster.com

I forgot to mention that I'm using Access 2007

Thanks Stefan for the input...I agree with you that it works fine in Access
2003. I had the same script in 2003 application.The app was migrated to 2007,
the proper namespace/class must be specified thus Dim f As Scripting.Folder


Stefan said:
hi,
Given this declaration i got runtime error: 13 Type Mismatch.
variable origin is a string containg the folder location.
[quoted text clipped - 3 lines]
Dim afile As File
Set f = fs.GetFolder(origin)
hmm, first of all: don't use the As New syntax.

This works for my using Access 2003 with a reference set to "Microsoft
Scripting Runtime":

Option Compare Database
Option Explicit

Public Sub test()

Dim fs As FileSystemObject
Dim f As Folder
Dim afile As File

Set fs = New FileSystemObject
Set f = fs.GetFolder("C:\Temp")

MsgBox f.Name

End Sub

mfG
--> stefan <--
 
S

Stefan Hoffmann

hi,
Thanks Stefan for the input...I agree with you that it works fine in Access
2003. I had the same script in 2003 application.The app was migrated to 2007,
the proper namespace/class must be specified thus Dim f As Scripting.Folder
It is basically a good idea to use the correct prefixes for all object
type variables...


mfG
--> stefan <--
 

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