Error converting form's macros to VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Petrol
    Contributor
    • Oct 2016
    • 306

    #1

    Error converting form's macros to VB

    My application opens with a Switchboard based on the one created by Access's standard Switchboard manager - that is, a form driven by tbl SwitchboardItem s, with an OnOpen macro to initialise its variables and a command button which invokes an OnClick macro to initiate the required action.

    This has worked fine, but I now want to convert the macros to code procedures to give me a little more flexibility. When I click "Convert Form's Macros to Visual Basic" on the Design tab, it does so and displays "Conversion Finished", but then when the form is opened it gives the On Open error "Procedure declaration does not match the description of event or procedure having the same name" (screenshot attached).
    Even if I delete the entire contents of the resultant Sub, it still gets the same error. If I delete the OnOpen macro before converting the macros to VB, it get the same error at the On Load, OnCurrent, OnClose stages.

    I have converted macros to VB code in other forms successfully.
    Attached Files
  • PhilOfWalton
    Recognized Expert Top Contributor
    • Mar 2016
    • 1430

    #2
    Hi Petrol

    Open the form in Design View and see if the code compiles.

    Phil

    Comment

    • Petrol
      Contributor
      • Oct 2016
      • 306

      #3
      No it doesn't, the message ("Microsoft Access was unable to create the ACCDE ...") implying too many table IDs.
      However, note that I said that the same error occurs even when I take all the compiled code out of the sub, leaving just the following two statements:
      Code:
      Private Sub Form_Open(Cancel As Integer)
      
      End Sub
      As shown in the post on the original screenshot, the error on opening is "Procedure declaration does not match the description of event or procedure having the same name" However the procedure declaration,
      Private Sub Form_Open(Cance l As Integer)
      looks fine to me.

      Comment

      • PhilOfWalton
        Recognized Expert Top Contributor
        • Mar 2016
        • 1430

        #4
        Well obviously the error message has nothing to do with compiling. That error message is related to converting an Accdb to an Accde.

        Are you sure you just tried a compile in the VBA--->Debug--->Compile your project name?

        Phil

        Comment

        • Petrol
          Contributor
          • Oct 2016
          • 306

          #5
          Well no, Phil, I did it by creating an accde file, which I understood compiles the code. However when I do it by VBA-Debug-Compile I get the same message as before: "Compile Error: Procedure declaration does not match description of the event or procedure having he same name".

          Comment

          • Petrol
            Contributor
            • Oct 2016
            • 306

            #6
            I mean "the same name"

            Comment

            • PhilOfWalton
              Recognized Expert Top Contributor
              • Mar 2016
              • 1430

              #7
              Right, two processes are completely different. You can't make an Accde unless the Accdb compiles without errors. So always compile first.

              Don't forget you can't modify forms & reports in an Accde, so that should only be created when you want to distribute your DB.

              Does the compiler highlight the error line.

              I'm off sailing for the rest of the day, so probably won't get back to you.

              Phil

              Comment

              • Petrol
                Contributor
                • Oct 2016
                • 306

                #8
                Looks like it should be a nice day for it, too. Enjoy!

                Yes I understand that. I've released the DB at the beginning of this year to selected other users in our organisation, though I'm still adding enhancements. All releases to others have been accde, which have always compiles without trouble - and still do, except when I convert the macros to VBA. It's clearly that process which is going wrong.

                And no, it doesn't highlight any error line. It doesn't even open the code module. When I click "Convert Form's Macros to Visual Basic" on the Design tab, it does so and displays "Conversion Finished", but then when the form is opened it gives the On Open error "Procedure declaration does not match the description of event or procedure having the same name" (screenshot attached to OP).

                Even if I delete the entire contents of the resultant Sub, it still gets the same error. If I delete the OnOpen macro before converting the macros to VB, it get the same error at the On Load, OnCurrent, OnClose stages.

                Comment

                • PhilOfWalton
                  Recognized Expert Top Contributor
                  • Mar 2016
                  • 1430

                  #9
                  Sitting here on the boat, having a G & T so, probably you aren't going to get much sense.

                  So you've done the conversion. Forget opening any forms. Can you open any forms in design view and can you open any modules?

                  Phil

                  Comment

                  • Petrol
                    Contributor
                    • Oct 2016
                    • 306

                    #10
                    Still on the boat at ... what, 10pm?

                    Yep. No probs with any other forms, reports, modules etc. Just the switchboard. I'm gradually chopping little bits out of its macros to see what's causing ghe problem ... but as I said, if I delete all the contents of the resultant VBA code after conversion it still claims not to like the procedure name. Must be a bug in Access, surely

                    Comment

                    • PhilOfWalton
                      Recognized Expert Top Contributor
                      • Mar 2016
                      • 1430

                      #11
                      Hey, aren't I allowed a day off. Come home tomorrow.

                      It's worth checking the names of all the fields on the form, and see if the corresponding subroutine has the correct parameters.

                      For example
                      Code:
                      Private Sub Form_Open (Cancel as Integer)
                      would probably yield the sort of error you describe.

                      Good Night

                      Phil

                      Comment

                      • PhilOfWalton
                        Recognized Expert Top Contributor
                        • Mar 2016
                        • 1430

                        #12
                        A further thought

                        Have you got
                        Code:
                        Option Compare Database
                        Option Explicit
                        at the top of EVERY module. The Option Explicit ensures you don't write code about anything that hasn't been defined.

                        If these are not there, add them and recompile

                        Phil

                        Comment

                        • Petrol
                          Contributor
                          • Oct 2016
                          • 306

                          #13
                          I'm pretty sure I have.
                          I'm just looking into Decompile.

                          Comment

                          • Petrol
                            Contributor
                            • Oct 2016
                            • 306

                            #14
                            This is getting ridiculous! To recap, my Switchboard form has both the original MS Switchboard macros plus a couple of VBA subs I've added, OnLoad and OnClose. As stated in the Original Post, when I click "Convert Form's Macros to Visual Basic" on the Design tab, it does so and displays "Conversion Finished", but then when the form is opened it gives the On Open error "Procedure declaration does not match the description of event or procedure having the same name". It didn't open or display any code modules, but when I did so manually the OnOpen sub does have the correct name and procedure declaration: Private Sub Form_Open(Cance l As Integer) .

                            1. I reloaded Access and the DB and deleted all macros, then clicked "Convert Form's macros to Visual Basic". It now gave the same fault (see image attached to original post) but this time referring to the OnLoad and OnClose procedures - which had never been macros and were still the same VBA code as before.

                            2. I reloaded the DB and deleted all macros and event procedures entirely, then ran "Convert Form's macros ..." again. I then created a new empty OnLoad event procedure, consisting only of the procedure declaration and the End Sub statement. I saved, exited and reloaded the DB, Compacted it, closed and decompiled and recompiled it. The Compile failed with the same error, "Procedure declaration does not match the description of event or procedure having the same name". Likewise, attempts to open the form fail with the same error.

                            The MSDN Help site (here) suggests that this may be caused by a mismatch of the number or type of parameters. However there is no mismatch in either name or parameters - one system-generated Integer parameter for the Open sub, none for the Load or Current or Close ones.

                            I think I'll just have to give up the idea of converting the macros to VBA. :-(

                            Comment

                            • PhilOfWalton
                              Recognized Expert Top Contributor
                              • Mar 2016
                              • 1430

                              #15
                              No, Don't give up. VBA is so much more powerful.

                              So Can I suggest 3 options.
                              1) After you have done your conversion, create a new database and import all your tables and queries into it. Then 1 by 1 import your forms and reports and compile after each import. The problem may not be with your switchboard form.

                              2) Set up a Skype contact with me and I can look at what you are doing by sharing screens .

                              3 Send be a copy of your Db and I will look at it.
                              Obviously for the latter 2 options, you will need to send me a private message.

                              Phil

                              Comment

                              Working...