dcsimg
Results 1 to 12 of 12

Thread: [RESOLVED] FileSystemOnject/ Run-Time error 13 Type Mismatch

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2009
    Location
    Fort Worth, TX
    Posts
    38

    Resolved [RESOLVED] FileSystemOnject/ Run-Time error 13 Type Mismatch

    Ok friends, I've searched the internet and these archives and am at a real loss on this one.

    I'm developing a pretty complex MS Access database with a VB6 front end and one thing that I need to do in the front end is to pull up and display the file directory for an existing folder on either the host PC or on a shared drive on our server. After rooting around I settled on using a FileSystemObject routine as the simplest approach. I opened up a brand new VB6 project to test the routine out, and the following subroutine works perfectly, displaying the list of all files in the specified folder in a list box.

    Code:
    Public Sub GetFolderFileList()
    
    Dim oFileSystem As New FileSystemObject
    Dim oFolder As Folder
    Dim oCurrentFile As File
    Dim oFileColl As Files
    
    Set oFolder = oFileSystem.GetFolder("d:\data\bradfb\Desktop\CR Disposition\")
    
    Set oFileColl = oFolder.Files
    
    If oFileColl.Count > 0 Then
    
        With lstFiles
        
            For Each oCurrentFile In oFileColl
            
                .AddItem oCurrentFile.Name
                
            Next
            
            .ListIndex = 0
            
        End With
        
    End If
    
    Set oFileSystem = Nothing
    Set oFolder = Nothing
    Set oFileColl = Nothing
    Set oCurrentFile = Nothing
        
    End Sub
    Now, here's the catch!! When I paste this WORKING SUBROUTINE into my database front end, it give me a "Run-time Error 13 Type Mismatch" on the Set oFolder = oFileSystem.GetFolder line of code. I've confirmed (and re-confirmed!!) that I have a reference set to the Microsoft Scripting Runtime and tried most everything else that I can think of, all with no success. Can anyone help me??

    Chief Brad

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    40,747

    Re: FileSystemOnject/ Run-Time error 13 Type Mismatch

    Make your declarations more specific by also including the library, as it seems that there is at least one other item with the same data type name - and VB has determined that you want the other one.

    I don't know what the name of the Microsoft Scripting Runtime is (use the Object Browser [F2] to check), but it will be something like this:
    Code:
    Dim oFolder As Scripting.Folder

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2009
    Location
    Fort Worth, TX
    Posts
    38

    Re: FileSystemOnject/ Run-Time error 13 Type Mismatch

    Thanks Si - -

    I had looked at that before and everything I read said that the "scripting" library name was optional, BUT I had tried that anyway with no success. I just tried it again as a sanity check and again no luck. I've also searched through the software looking for another datatype with the same name, and again no luck.

    Any other thoughts??

    Brad

  4. #4
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: FileSystemOnject/ Run-Time error 13 Type Mismatch

    It works just fine for me, even with your folder paths (which I recreated on my PC).

    How do you call this sub and from where?
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2009
    Location
    Fort Worth, TX
    Posts
    38

    Re: FileSystemOnject/ Run-Time error 13 Type Mismatch

    Hi Hack - -

    Yeah, as I said in my original post, I originally wrote the subroutine in a totally seperate VB6 project, all by itself, just to test the code, and it works fine. But when I pasted the subroutine AS IS from that small project to my big project, it will no longer work. No changes of any kind . . . . it just won't work.

    I am calling the routine right now from a command button on the same form.

    Brad

  6. #6
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: FileSystemOnject/ Run-Time error 13 Type Mismatch

    So, you have a Public sub in the declarations section of a form.

    Why isn't it a Private sub if it is on a form, and, if it is to be public, why isn't it in a module?

    Just for yucks, change the name of it, on your form, from GetFolderFileList to GetFileList.

    Do you have another GetFolderFileList in a module somewhere?
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2009
    Location
    Fort Worth, TX
    Posts
    38

    Re: FileSystemOnject/ Run-Time error 13 Type Mismatch

    Sorry, still no luck.

    The Add Procedure under the Tools drop down menu defaults to Public, and I'll admit that I'm not very cautious about setting it back to Private when opening a new procedure. I may just be lucky that it's never caused me a problem before.

    I've checked all of my forms and my lone module and can't find a name conflict for either my subroutine name (which I just tried renaming) or any of my objects, which I've also tried renaming.

    Brad

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    40,747

    Re: FileSystemOnject/ Run-Time error 13 Type Mismatch

    Quote Originally Posted by Chief Brad View Post
    I had looked at that before and everything I read said that the "scripting" library name was optional,
    Omitting the library is optional except if the name is used in more that one library you have referenced - otherwise you get errors like this one (I see it most often with "Recordset" when the user has two or more database related references).

    To be on the safe side you should always specify the library for anything that needs a reference.
    BUT I had tried that anyway with no success. I just tried it again as a sanity check and again no luck.
    Did you do it for all of the declarations in that routine?

  9. #9

    Thread Starter
    Member
    Join Date
    Nov 2009
    Location
    Fort Worth, TX
    Posts
    38

    Re: FileSystemOnject/ Run-Time error 13 Type Mismatch

    BINGO!!

    Adding the Scripting library name before the Folder, File, and Files declarations did the trick!!

    Thanks Si and Hack for all of your suggestions.

    Now on to other things . . . . . .

    Chief Brad

  10. #10
    New Member
    Join Date
    Sep 2016
    Posts
    2

    Red face Re: FileSystemOnject/ Run-Time error 13 Type Mismatch

    Quote Originally Posted by Chief Brad View Post
    BINGO!!

    Adding the Scripting library name before the Folder, File, and Files declarations did the trick!!

    Thanks Si and Hack for all of your suggestions.

    Now on to other things . . . . . .

    Chief Brad

    Hi Chief Brad, Could you show the code fix you did on
    "Adding the Scripting library name before the Folder" as i m a total beginner in vb6

    thanks in advance!

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    40,747

    Re: FileSystemOnject/ Run-Time error 13 Type Mismatch

    Welcome to VBForums

    Chief Brad hasn't been around for a while, but what he seems to mean is:
    Code:
    Dim oFolder As Scripting.Folder
    Dim oCurrentFile As Scripting.File
    Dim oFileColl As Scripting.Files
    Quote Originally Posted by Natsl View Post
    i m a total beginner in vb6
    If you don't have a specific reason to learn VB6 (aka VB 1998), such as needing to use it for school/work, then I'd recommend using a more modern language instead (one which is still supported, and has more features built-in).

    There are lots of possible alternatives, such as VB.Net (eg: VB 2015) which you can get for free.

  12. #12
    New Member
    Join Date
    Sep 2016
    Posts
    2

    Re: FileSystemOnject/ Run-Time error 13 Type Mismatch

    Thanks si_the_geek for your explanation Got it .

    ps:sorry took long to reply. Haven't been using this website for some time.

    Supporting some legacy code so no choice.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width