Results 1 to 4 of 4
  1. #1
    Mister-B is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    31

    Angry Running VBA code in a form from a macro

    The title says it all. I've got a form with many VBA codes that do various things. How can I get a macros to run the code? I'm using the run code command but I can get the synthax right. The code is in the form "Daten" and one of the codes is called "Befehl2606_Click". Can anybody help. It's driving me crazy.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Try your code in a general Module rather than in a forms module and declare it as Public not Private
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Only functions can be called from a macro, no subs.
    Also, the function cannot be located in a Class Module.
    If the code you want to run lies in a class module (behind a form), you can create a Function in a code module to call the target code.
    The target code behind the form must be defined as PUBLIC, not PRIVATE.
    See this attachment:MacroCall-ClassModule.zip

  4. #4
    Mister-B is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    31
    Yes, thank you. Using a Public Function to call the code in the form works fine.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 11-28-2017, 07:28 AM
  2. Replies: 1
    Last Post: 02-18-2016, 05:57 AM
  3. Running Code from a Module in a Macro
    By ReadyReckoners in forum Modules
    Replies: 2
    Last Post: 05-08-2013, 04:45 AM
  4. Replies: 4
    Last Post: 05-06-2013, 12:56 PM
  5. Replies: 1
    Last Post: 12-13-2012, 01:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums