Assigning converted Access macros

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Drisconsult
    New Member
    • Mar 2008
    • 3

    Assigning converted Access macros

    Hello All
    I am new to VBA. I have just begun converted all my Access macros to VBA. As I understand it they are converted to Modules. How do I assign the converted module to the command button that originally launched the macro, or do I have to create a new button or label?

    For example, I have 12 command buttons that open forms from a menu, I now wish to convert the macros to VBA and have each form launched using VBA.

    Regards
    Terence
    London
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by Drisconsult
    Hello All
    I am new to VBA. I have just begun converted all my Access macros to VBA. As I understand it they are converted to Modules. How do I assign the converted module to the command button that originally launched the macro, or do I have to create a new button or label?

    For example, I have 12 command buttons that open forms from a menu, I now wish to convert the macros to VBA and have each form launched using VBA.

    Regards
    Terence
    London
    When you Convert Macros to VBA:
    1. Each selected Macro gets converted to a Public Function contained within a Module named 'Converted Macro' - <Macro Name>. For instance, let's assume you convert a Macro named Macro1. A Public Function named Macro1 will now exist in a Module named Converted Macro - Macro1.
    2. To execute this converted Macro within the context of a Command Button, only now as VBA code, simply Call it in the Click() Event of a Command Button. You can use this Syntax since the Function will not return a value.
      [CODE=vb]
      Private Sub cmdTestButton_C lick()
      Call Macro1
      End Sub[/CODE]

    Comment

    • Drisconsult
      New Member
      • Mar 2008
      • 3

      #3
      Many thanks for replying to my query

      I have changed the macro1 to the name of my macro, which is mcrOpen 01 but get an error referring to an ambiguous name detected: mcrOpen 01. What am I doing wrong?

      Regards
      Terence

      Comment

      • Drisconsult
        New Member
        • Mar 2008
        • 3

        #4
        Hello All

        I have successfully assigned my VBA converted macros to labels using the following code:
        Code:
        Private Sub LABEL01_Click()
            Call mcrOPEN01
        End Sub
        But I am having trouble assigning the VBA converted macro to a command button.

        Regards
        Terence

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32656

          #5
          Terence, Access has names for procedures that are triggered by events on a control.

          If you have a CommandButton control called, say, [cmdConvert], then the code that will be executed (when it is clicked) will be called cmdConvert_Clic k() and it will be stored in the module associated with the form that [cmdConvert] is in.

          To create the stub for this procedure simply open the form in design view; select [cmdConvert]; Open the Properties pane (Alt-Enter); Navigate down to [On Click]; In the DropDown select [Event Procedure]; Click on the elipsis button to the right.

          In here you can enter (or paste in) the code you require to be executed.

          Comment

          Working...