MS Access VBA "Automation Error"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • billelev
    New Member
    • Nov 2006
    • 119

    MS Access VBA "Automation Error"

    I have the following vba code that returns the "date modified" field from a file, specified in filepath:

    Code:
    Function GetFileModifiedDate(filepath As String) As Date
    
        Dim fs, f
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.GetFile(filepath)
    
        GetFileModifiedDate = f.datelastmodified
    
    End Function
    On one machine it runs without any problems, but on another I encounter the following error message:

    Code:
    Run-time error (8007007e) 
    Automation error 
    The specified module could not be found.
    Does anyone know how to fix this?

    Thanks,
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by billelev
    I have the following vba code that returns the "date modified" field from a file, specified in filepath:

    Code:
    Function GetFileModifiedDate(filepath As String) As Date
    
        Dim fs, f
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.GetFile(filepath)
    
        GetFileModifiedDate = f.datelastmodified
    
    End Function
    On one machine it runs without any problems, but on another I encounter the following error message:

    Code:
    Run-time error (8007007e) 
    Automation error 
    The specified module could not be found.
    Does anyone know how to fix this?

    Thanks,
    1. Set a Reference to the Microsoft Scripting Runtime Library.
    2. Rename your Function to:
      [CODE=text]GetFileModified Date_2[/CODE]
    3. Modify the Function code to:
      [CODE=vb]
      Function GetFileModified Date_2(filepath As String) As Date

      Dim fs As FileSystemObjec t
      Dim f As File

      Set fs = CreateObject("S cripting.FileSy stemObject")
      Set f = fs.GetFile(file path)

      GetFileModified Date_2 = f.DateLastModif ied
      End Function[/CODE]
    4. Let me know how you make out.

    Comment

    • billelev
      New Member
      • Nov 2006
      • 119

      #3
      Thanks for your reply. I tried what you suggested but with no success. Given that the original code worked on one machine, but not the other. Would this not imply that the issue is with the machine, rather than the code?

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by billelev
        Thanks for your reply. I tried what you suggested but with no success. Given that the original code worked on one machine, but not the other. Would this not imply that the issue is with the machine, rather than the code?
        Given that the original code worked on one machine, but not the other. Would this not imply that the issue is with the machine, rather than the code?
        It would appear that way. I was almost sure that 1 of the three suggestions would have solved the problem, but obviously not (LOL). I'll put my Thinking Cap on again and get back to you if I arrive at a solution.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32656

          #5
          When it said "The specified module could not be found.", were there any clues as to what the module referred to might be?

          Comment

          • billelev
            New Member
            • Nov 2006
            • 119

            #6
            No, although it has to be associated with the code above...

            I have spent a lot of time searching for a solution on the internet, and this is certainly not an isolated problem. Many people have had similar issues, with seemingly good code not working on one particular machine.

            One such post is ** Link removed as per site rules **

            Unfortunately, none of the forums I have visited have a posted solution!
            Last edited by NeoPa; May 21 '08, 02:36 PM. Reason: Against the site rules to link to other forum sites

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32656

              #7
              Please remember not to link to other forum sites in your posts. I'm sure this was innocently done, but not allowed nevertheless.

              As for Access error messages, although they can sometimes be helpful, they are also quite famous for being completely unrelated to the issue (as in - entirely spurious).

              This can be particularly annoying when you find the solution which you only failed to find before because the error message actually indicated something completely different was at the root of the problem.

              Comment

              • billelev
                New Member
                • Nov 2006
                • 119

                #8
                Okay, it seems that there was some kind of problem with scrun.dll.

                I tried registering the dll again, using:

                Code:
                regsvr32 C:\WINDOWS\System32\Scrrun.dll
                in the CMD prompt. It is now working...

                Thanks for all your input.

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32656

                  #9
                  Excellent :) Thanks for posting that.

                  Just for general usage it can also be used as :
                  Code:
                  regsvr32 %WinDir%\System32\Scrrun.dll

                  Comment

                  • Vipul Kadia

                    #10
                    Hi billelev,
                    Thanks...
                    It really worked...

                    Comment

                    Working...