Page 1 of 3 123 LastLast
Results 1 to 15 of 33
  1. #1
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664

    Setting Up A Macro to run VBA code

    In the db that I have attached to this post, I am wondering how to setup the RunCode line in the
    addMiisingRows-MAC.

    The add missing rows function cannot just be called as:



    RunCode addMissingRows()

    That will not work.

    If one looks at the VBA code that would call addMissingRows-MAC
    and then the RunCode command within it then it should be obvious the function call
    addMissingRows, now has argumenta. That is what I am unsure of.

    How do I set this up with arguments in addMiisingRows-MAC.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    For starters, why would you run a macro that runs VBA? Why not just call the function instead of using RunMacro? On your other thread I thought we agreed that you were better off eliminating the macro from the middle.

    Second, that function has no arguments:

    Function addMissingRows()
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    That is exactly what I thought. but, I did not get the feeling that it was a good idea. I reverted to somethings that I knew works, even if it is clumsy. As I said if i use arguments, then how do I change the RunCode command? It cannot be the same as when the RunCode command that calls a function with no arguments. What is different?

    Also,U I beleive thta is what I must d when I run the function by just calling it.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

  4. #4
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    If you look at the pdf files you will see that addMissingRows does have arguments. I included a pdf of the source code to show that to you.

    Respectfully,

    Lou Reed

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    I'd say it's not a good idea to have the macro in the middle, just for the sake of it. It's clumsy and inefficient. That said, you'd change the RunCode command by adding the appropriate argument(s) inside the parentheses, as I showed on the other thread.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    The PDF showed the form open event, not the function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I think I know the answer to m own question. Just tell me if I am correct. If I run addMissingRpws from a macro the syntax is'

    addMissingRows()

    and ii it has arguments the syntax is now changed to reflect those arguments.

    addMissingRows(argument1,argument2)

    Is that all that must be changed?

    Any help appreciated. Thanks in advance.


    Lou Reed

  8. #8
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Here are two Snagit screenshots. They are pdf files.

    One shows a RunMacro command in some VBA code. It is calling the macro that calls the function FormHeading with no arguments.
    The second pdf file shows the original RunMacro command calling a macro that calls a FormHeading function that does have arguments.

    How do I modify the first pdf file (the one that calls the macro FormHeading-MAC and reflects its arguments)?

    Any help appreciated. Thanks in adavance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Quote Originally Posted by Lou_Reed View Post
    I think I know the answer to m own question. Just tell me if I am correct. If I run addMissingRpws from a macro the syntax is'

    addMissingRows()

    and ii it has arguments the syntax is now changed to reflect those arguments.

    addMissingRows(argument1,argument2)

    Is that all that must be changed?

    Any help appreciated. Thanks in advance.


    Lou Reed
    Yes, correct, though I wouldn't use the macro.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Quote Originally Posted by Lou_Reed View Post
    Here are two Snagit screenshots. They are pdf files.

    One shows a RunMacro command in some VBA code. It is calling the macro that calls the function FormHeading with no arguments.
    The second pdf file shows the original RunMacro command calling a macro that calls a FormHeading function that does have arguments.

    How do I modify the first pdf file (the one that calls the macro FormHeading-MAC and reflects its arguments)?

    Any help appreciated. Thanks in adavance.

    Respectfully,

    Lou Reed
    The change wouldn't be in the code calling the macro, it would be in the macro calling the function. But again, why complicate matters with the macro? Just call the function instead of the macro.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Okay, that seems like a good idea as I said before. However, I wanted to get started on it so I started VBA code to call a macro, then the macro calls a VBA function. It just is a way that I know. Now based on what you say I must have two macros it comes to calling FormHeading function. By that I mean that call it with no arguments and one that calls it with arguments. One macro that call FormHeading cannot do all the work, it must be at least two for the two instances that I just described.

    Is this correct?

    Also, when I call the function directly in the VBA code it is obviously Call Macro() or Call Macro(arguments1,arguments2, ...) depending on whether the call to the function has no arguments or one or more arguments.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Quote Originally Posted by Lou_Reed View Post
    Okay, that seems like a good idea as I said before. However, I wanted to get started on it so I started VBA code to call a macro, then the macro calls a VBA function. It just is a way that I know. Now based on what you say I must have two macros it comes to calling FormHeading function. By that I mean that call it with no arguments and one that calls it with arguments. One macro that call FormHeading cannot do all the work, it must be at least two for the two instances that I just described.

    Is this correct?

    Also, when I call the function directly in the VBA code it is obviously Call Macro() or Call Macro(arguments1,arguments2, ...) depending on whether the call to the function has no arguments or one or more arguments.
    The function either has arguments or it doesn't, so having 2 macros doesn't make any sense. And again, why bother with the macro? In VBA simply

    FormHeading

    or

    FormHeading 123, "abc"

    You can use Call if you want, it then requires parentheses.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    So something like

    DoCmd.RunMacro "FormHeading", , ""

    would be rewritten as:

    FormHeading ", ,""

    Any help appreciated. Thanks I advance.

    Respectfully,

    Lou Reed

    Please note that there are three sets of double quotes.

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Yes, though you only need the arguments if the function requires them.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #15
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Okay, but about those double quotes. What do I do with them? Consider the example that I showed to you.

    Respectfully,

    Lou Reed

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Help with NPV Macro Code in VBA
    By BigNasty in forum Macros
    Replies: 6
    Last Post: 11-21-2016, 10:39 PM
  2. Setting Code to Simple Numeric Age
    By wes9659 in forum Forms
    Replies: 6
    Last Post: 08-14-2014, 01:22 PM
  3. Setting Report Height In Code
    By ccordner in forum Reports
    Replies: 1
    Last Post: 12-07-2012, 10:26 PM
  4. VBA code/Macro help please.
    By Davidyam in forum Access
    Replies: 1
    Last Post: 02-26-2012, 09:59 PM
  5. Replies: 10
    Last Post: 01-04-2012, 01:43 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