• Convert to VB (A2K)

    Author
    Topic
    #392649

    When viewing a Form or Report in Design view (Access 2000), there is the ability to convert all Macros related to the Form/Report to Visual Basic.

    Tools | Macro | Convert To Visual Basic

    I stumbled across this in trying to gain some understanding as to how my Forms work and, hopefully, to get a little further down the road toward learning something about VBA. My question is, aside from the educational experience, what does this actually accomplish? Will the application run more efficiently as a result of this conversion, or are the existing Macros just as efficient?

    Blundering ahead, I actually did this conversion on one of my forms and all but crashed my app. (see attachment). I assume this occurred as a result of the Macro having already been converted to a Module at some point in the past. When I deleted the conversions, retaining the Macros, everything returned to normal. Some of the functionality of the form is based on Macro

    Viewing 1 reply thread
    Author
    Replies
    • #706089

      If you have macros that serve your purpose, there is no compelling need to convert them to VBA code. One of the main advantages of VBA code over macros is that it is much more flexible and powerful, and much easier to maintain, so when the moment comes that you have to modify the macros, you might consider converting them to code.

      When you convert all of the macros associated with a form to code, the references to the macros in the Event tab of the Properties window are replaced by [Event Procedure], so after testing that the code works as intended (important!), you can delete the macros.

      The other way round is less easy. If you remove code, the references in the Event tab of the Properties window won’t revert to the original macros.

      By the way, if you convert an individual macro to code, Access creates a standard module whose name begins with Converted Macro. This module is visible in the Modules tab of the database window, and it can be deleted normally.

      If you open a form in design view and select Tools | Macro | Convert Form’s Macros to Visual Basic, the code is placed in the form module (at least in Access 2002, I don’t have Access 2000); this module is not visible in the Modules tab. If you want to delete it, you must set the Has Module property of the form to No (in the Other tab of the Properties window.) You will lose ALL code behind the form this way.

      • #706109

        Digesting. . .

        1. My assumption is that I can delete all current Modules (with the prefix “Converted Macro-“)
        2. I can then go to each Form and use Tools | Macro | Convert to VB
        3. Delete each Macro associated with the Form

        After having done this, I can look at the [Event Procedure] to view (and learn from) the converted code. Should I decide to do this, I understand that I am not doing anything to immediately benefit the application, but only to “view” the code. Have I got that right?

        • #706127

          Correct, but as usual, keep a backup copy of the current version, just in case…

          • #706134

            Righty-O! (Backup, backup, backup. . .)
            Thanks for the guidance!

          • #706135

            Righty-O! (Backup, backup, backup. . .)
            Thanks for the guidance!

          • #706224

            A WORD OF CAUTION (for anyone following this thread).

            This process does not appear to work for Macro’s used in the Switchboard.
            If there is a way to do that, I have not discovered it. Deleting those Macro’s resulted in loss of Switchboard functionality. Thank God I was working in a copy!

            • #706231

              You’ll have to use the Switchboard Manager to edit the items to run code instead of running a macro.

            • #706241

              Funny you should mention that. . .I was just looking at “Run Code”, but didn’t know what “Function Name” referred to.

            • #706242

              Funny you should mention that. . .I was just looking at “Run Code”, but didn’t know what “Function Name” referred to.

            • #706232

              You’ll have to use the Switchboard Manager to edit the items to run code instead of running a macro.

          • #706225

            A WORD OF CAUTION (for anyone following this thread).

            This process does not appear to work for Macro’s used in the Switchboard.
            If there is a way to do that, I have not discovered it. Deleting those Macro’s resulted in loss of Switchboard functionality. Thank God I was working in a copy!

        • #706128

          Correct, but as usual, keep a backup copy of the current version, just in case…

      • #706110

        Digesting. . .

        1. My assumption is that I can delete all current Modules (with the prefix “Converted Macro-“)
        2. I can then go to each Form and use Tools | Macro | Convert to VB
        3. Delete each Macro associated with the Form

        After having done this, I can look at the [Event Procedure] to view (and learn from) the converted code. Should I decide to do this, I understand that I am not doing anything to immediately benefit the application, but only to “view” the code. Have I got that right?

    • #706090

      If you have macros that serve your purpose, there is no compelling need to convert them to VBA code. One of the main advantages of VBA code over macros is that it is much more flexible and powerful, and much easier to maintain, so when the moment comes that you have to modify the macros, you might consider converting them to code.

      When you convert all of the macros associated with a form to code, the references to the macros in the Event tab of the Properties window are replaced by [Event Procedure], so after testing that the code works as intended (important!), you can delete the macros.

      The other way round is less easy. If you remove code, the references in the Event tab of the Properties window won’t revert to the original macros.

      By the way, if you convert an individual macro to code, Access creates a standard module whose name begins with Converted Macro. This module is visible in the Modules tab of the database window, and it can be deleted normally.

      If you open a form in design view and select Tools | Macro | Convert Form’s Macros to Visual Basic, the code is placed in the form module (at least in Access 2002, I don’t have Access 2000); this module is not visible in the Modules tab. If you want to delete it, you must set the Has Module property of the form to No (in the Other tab of the Properties window.) You will lose ALL code behind the form this way.

    Viewing 1 reply thread
    Reply To: Convert to VB (A2K)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: