I'm getting error message on a form that I've inherited

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Anthony97
    New Member
    • Aug 2009
    • 24

    I'm getting error message on a form that I've inherited

    I get the following error message

    Run-time error '2455' you entered invalid reference to the property FileSearch

    '************** *************** *************** *************** *************** *************
    Code:
    Set fs = Application.FileSearch
    With fs
        ' Set search directory and file type to search for
        .LookIn = strFileLocation
        .FileName = strFileName
        
        ' Loop through found files and import
        If .Execute > 0 Then
            intNumFiles = .foundfiles.Count
            For i = 1 To .foundfiles.Count
                'strFileName = Right(.foundfiles(i), 12)
    Last edited by NeoPa; Sep 3 '09, 03:09 PM. Reason: Please use the [CODE] tags provided.
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Looks like you need to reference "Microsoft Office xx.x Object Library".
    In VBA window MainMenu -> Tools -> References.

    Comment

    • Megalog
      Recognized Expert Contributor
      • Sep 2007
      • 378

      #3
      If you're using Access 2007, then I'm sorry to inform you that the FileSearch object no longer exists. Yes, the help file is still there for it, and it might still exist in the object browser, but it -has- been removed.

      Error message when you try to run the FileSearch function in Access 2007 (Microsoft Support kb/935402)

      Comment

      • Anthony97
        New Member
        • Aug 2009
        • 24

        #4
        was that functionality available in access 2003? I think this might have been copied over from Access 2003

        Comment

        • Megalog
          Recognized Expert Contributor
          • Sep 2007
          • 378

          #5
          Yep, it was there previously. This was an undocumented (and really, unwarranted) removal for 2007. Google "Application.Fi leSearch" and you'll see a whole bunch of posts from angry/frustrated programmers.

          If you look at the link I previously posted, microsoft has a few suggestions under the Resolution section that involve the FileSystemObjec t (FSO) Class. This is probably the best starting point to repairing whatever process they broke in your db.

          Comment

          • FishVal
            Recognized Expert Specialist
            • Jun 2007
            • 2656

            #6
            If you want to go with FSO, then just for starters you may read a series of articles in insights section of the forum concerning "Scripting Runtime" library.
            This one is the first.

            Comment

            • Anthony97
              New Member
              • Aug 2009
              • 24

              #7
              I've did additional research and a lot of the suggestions I've found online don't work. I am not well based in VBA, but I would think there has to be a way to substitute something else for Set fs=Application. FileSearch, the problem is finding an example that is close to what I'm trying to do.

              What the form is supposed to do and did in Access 2003 is:
              1) you enter a specific file which is in a csv format
              2) click a button which will delete all old records from access table associated with csv file type
              3)then it imports new records from the .csv file

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32633

                #8
                Have you actually explained what you want help with yet? It seems not.

                Would I be right in thinking you are simply trying to import a specified CSV format file into a table in your database? If so, this is relatively straightforward . This doesn't require FileSearch though, so I'm still a little lost as to where you're coming from.

                Comment

                • Anthony97
                  New Member
                  • Aug 2009
                  • 24

                  #9
                  I asked did anyone know of a way to substitute something else for

                  Set fs=Application. FileSearch

                  This functionality existed in Access 2003 and now doesn't exist in Access 2007.. That was the question as stated earlier in the post thread.

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32633

                    #10
                    Originally posted by Anthony97
                    I asked did anyone know of a way to substitute something else for

                    Set fs=Application. FileSearch

                    This functionality existed in Access 2003 and now doesn't exist in Access 2007.
                    Not in the original post clearly.
                    Originally posted by Anthony97
                    That was the question as stated earlier in the post thread.
                    If you're happy to limit the scope to that specific question then I'm not sure we can be more help (I certainly cannot limit my advice to such narrow boundaries).

                    Good luck.

                    Comment

                    • Megalog
                      Recognized Expert Contributor
                      • Sep 2007
                      • 378

                      #11
                      You're not going to be able to find a replacement that you can simply drop in and have your code work as it did before. Any of the 'replacements' you've found on the net have been tweaked or modified to death to fit people's various needs.

                      If I were you I'd start with Allen Browne's ListFiles method. This would generate a list of files into a collection, that you could then loop through and import.

                      Comment

                      Working...