Sub or Function not defined problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    Sub or Function not defined problem

    I have the following lines of code among others in my database
    Code:
    Dim modModule As CodeModule
    Set modModule = Application.VBE.ActiveVBProject.VBComponents(strModule).CodeModule
    lngStartLine = modModule.ProcStartLine(strProcedure, vbext_pk_Proc)
    When this code runs, I'm getting an error message highlighting line 3 saying "Sub or Function not defined". If I hover over strProcedure, I get the proper value. If I hover over vbext_pk_Proc I get the value 0 (as I should). If I hover over the .ProcStartLine, it shows the same error. I have the reference set to Microsoft Visual Basic for Applications Extensibility 5.3. If I go to the Object Browser, it lists ProcStartLine as one of the properties of the CodeModule object. I even get intellisense for it. So why am I getting this error message? I have even tried removing the reference and setting it again. It works on another database, but not on this one. Any ideas?
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #2
    What is strModule? What version of Access are you running? Do you have multiple versions installed on that machine?

    Jim

    Comment

    • TheSmileyCoder
      Recognized Expert Moderator Top Contributor
      • Dec 2009
      • 2322

      #3
      Could you be running it on an empty code module`?

      Comment

      • Seth Schrock
        Recognized Expert Specialist
        • Dec 2010
        • 2965

        #4
        This is just an excerpt from a larger project described in this post: How to navigate to a specific procedure in a module or class module. I got it to work in one database, but when I tried to copy it over to another database, it won't work.

        strModule is a variable containing the name of the module to which I want to navigate.

        @TheSmileyCoder I'm not sure which way you are asking. The code is being run in a module that only has this one procedure in it. The module that I'm referencing also has code in it.

        Comment

        • TheSmileyCoder
          Recognized Expert Moderator Top Contributor
          • Dec 2009
          • 2322

          #5
          I see. That kinda code is often seen where you loop through all the modules. My line of thought was that maybe one of the modules being looped over was empty, and thus had no procedure.

          Have you tried a decompile on the app?

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32662

            #6
            ProcStartLine seems to be 2010 and forwards only. Which version are you running with?

            Do you have references set to all the libraries you need?

            Is the installation of Access set up to trust programming access to the project in the options?

            Comment

            • Seth Schrock
              Recognized Expert Specialist
              • Dec 2010
              • 2965

              #7
              I'm using Access 2010 both on the working database and on the non-working database. I find the function in the Object Browser, so I would assume that I have the reference needed. And I do have the database setup in a trusted location.

              I will try to decompile it tomorrow when I go to work.

              Comment

              • TheSmileyCoder
                Recognized Expert Moderator Top Contributor
                • Dec 2009
                • 2322

                #8
                Does the "trouble"so me database compile without issues?

                Comment

                • Seth Schrock
                  Recognized Expert Specialist
                  • Dec 2010
                  • 2965

                  #9
                  I decompiled it and then compiled it again. It compiled without any issues (as it did before) and I'm still getting the same error message.

                  Comment

                  • TheSmileyCoder
                    Recognized Expert Moderator Top Contributor
                    • Dec 2009
                    • 2322

                    #10
                    At the risk of offending your intelligence :)

                    And you have double checked that the procedure name in strProcedure actually exists in the module?

                    Comment

                    • Seth Schrock
                      Recognized Expert Specialist
                      • Dec 2010
                      • 2965

                      #11
                      Ouch. That hurts. It didn't exist :( The line that I was parsing was
                      Code:
                      Error 3061 has occured in procedure [cmdDelete_OnClick] in module [Form_frmEmployee] on line [130] Too few parameters. Expected 1.
                      Somehow the name of the procedure was entered as cmdDelete_OnCli ck instead of cmdDelete_Click . I guess that I didn't even think to question that since it was saying that it couldn't find the sub or function. Even when I first checked I didn't notice the OnClick difference.

                      Thanks to everyone for your help and thank-you Smiley for pointing out my error. :)

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32662

                        #12
                        Originally posted by Seth
                        Seth:
                        Ouch. That hurts. It didn't exist :(
                        I feel that. That's always a hard one to spot actually. I guess we all understand how hard as we've all done it ourselves before.

                        Comment

                        Working...