Results 1 to 4 of 4

Running VBA code in a form from a macro

  1. #1
    Mister-B is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    4

    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 is offline MS Community Contributor
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    1,943
    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.
    Not everyone can access an accdb, you may reach a broader audience by attaching in mdb format.

    Bob Fitzpatrick

    I have never failed. I have found a thousand ways that do not work!

    Microsoft Community Contributor Award (2011)



  3. #3
    davegri is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    1,122
    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 Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    4
    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, 06:28 AM
  2. Replies: 1
    Last Post: 02-18-2016, 04:57 AM
  3. Running Code from a Module in a Macro
    By ReadyReckoners in forum Modules
    Replies: 2
    Last Post: 05-08-2013, 03:45 AM
  4. Replies: 4
    Last Post: 05-06-2013, 11:56 AM
  5. Replies: 1
    Last Post: 12-13-2012, 12: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
  •  
Tech Forums: Microsoft Office Forums