Page 4 of 5 FirstFirst 12345 LastLast
Results 46 to 60 of 68
  1. #46
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You appeared to be directing your follow-up question to JoeM, but perhaps he isn't around. I read the response that suggested calling the code from a macro as his interpretation of what you wanted to do: "You want to run the VBA code you come up with from a Macro".



    If that's not the case, you're certainly correct that calling it directly from VBA would be better than using a macro. Giving the function a different name than the macro isn't required, but it would avoid potential confusion.

    Regarding "where is the source for Function MyCode()? In the navigation pane?", you would see the module the function is contained in, not the function itself. They can't have the same name.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  2. #47
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Thanks very much for your quick reply. As far as naming the converted macro's VBA a different name well does the software do that when it starts off in the name of the code:

    "Converted Macro"?

    That is certainly a different name than the macro. The prefix "Converted Macro" sees to that.
    And just keep the source in the navigation window? That is where the macro to VBA software put it.

    Thanks for your reply.


    Respectfully,

    Lou Reed

  3. #48
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The function will be named the same as the macro, and the module is named "Converted...". You're comparing the module name to the macro name, you should be comparing the function name, as that's what the suggestion referred to. A module can contain many functions. I just tested, and a macro named Macro1 was converted to a function with the same name: "Function Macro1()", in a module named "Converted Macro- Macro1"

    I suppose it's personal preference, but if I converted macros to VBA, I'd copy the code elsewhere and delete the module named "Converted...". And as JoeM suggested, I wouldn't use the same name for the function, unless perhaps if the macro had a reasonably descriptive name AND I was deleting the macro. I wouldn't want 2 objects with the same name, even if Access allowed it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #49
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    In the zipped file that I attached is the db that I have been working on. The db crashes when I open it (see pdf files) and it is not clear why. I will go back and give the function a different name than the macro, but I do not think it is the reason the db crashes now when I open it.

    The db just crashes and nothing more. I just need to know why.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  5. #50
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    See the problem (what the code calls vs what exists):

    Form Heading - MAC
    Form Heading-MAC
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #51
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I saw that on early and I went back and corrected them all or so I thought; that was why it was so perplexing.

    I will check again.

    Thanks for your input.


    Respectfully,


    Lou Reed

  7. #52
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Okay, I did as you suggested. Now I get another message. I am not sure what it is saying or even if it is an error.

    The relevant files are attached.

    Also, do you have an internet reference that explains the difference between function names and module names. It just seems confusing. I know the difference between file names and the names of subprograms in that file. I am assuming it is similar.


    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  8. #53
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Having spaces (and symbols) in object names makes this type of thing more likely to happen. At a glance, you didn't notice that there were spaces in one and not the other.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #54
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I don't know of a good reference offhand. Basically the module is a bucket that holds subs and functions. You're always calling a sub or function by name, not the module that contains it.

    The error is because your macro calls a function named "Form Heading _ MAC", which doesn't exist. There is one named "FormHeading".
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #55
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Yes, I see your point. Then how do you call a function within a module and not avoid calling the module.

    I am just taking what the macro to VBA translator did. I admit that I am screwing up names, but once that is done should not things work within the parameters of the macro to VBA translation?

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

  11. #56
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Well, behind the scenes Access will load the module, but you don't worry about that, you just call the function. I might have a module named "basPublicFunctions" in my apps. There could be numerous functions in that module. Nowhere in my code will you see "basPublicFunctions", you'll just see the name of the particular function being called. That's why you can't have two functions with the same name, even if in different modules. The module name is irrelevant, it's just a bucket to hold the functions.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #57
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I went back and made sure all dashes were at mid-level - not too high and not to low. I also went back and changed any and all Form Heading-MAC to FormHeading-MAC. I even checked the RunCode command in the FormHeading-MAC. It still gives me the same error. This one defeats me.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  13. #58
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I see your point (I think). I am not avoiding putting the VBA code somewhere else. I am going to, but where to put it? It is not associated with any form or it is associated with more than one form. If the function Form Heading is used in two (or more than one) different sets of code then do I put it in twice? That seems like what you are saying.

    Is there some place that I can put it in and it is used by all?

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

  14. #59
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can't open the attachment right now, but try changing the RunCode to:

    FormHeading()

    In other words, use the name of a function that exists.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #60
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by Lou_Reed View Post
    Is there some place that I can put it in and it is used by all?
    They can be in any standard module. I typically have a module named "basPublicFunctions", or several of them grouped appropriately (basARFunctions, basReportFunctions, etc).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 4 of 5 FirstFirst 12345 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Converting Macros To VBA in 2013 Office
    By data808 in forum Access
    Replies: 8
    Last Post: 06-17-2014, 02:37 AM
  2. Wizard - Create code Code vs. Macros?
    By runbear in forum Forms
    Replies: 3
    Last Post: 01-08-2014, 12:52 PM
  3. VBA code for macros
    By marcvanderpeet12 in forum Access
    Replies: 1
    Last Post: 10-31-2013, 06:24 AM
  4. Converting SQL to VBA code
    By Davidyam in forum Access
    Replies: 3
    Last Post: 04-18-2012, 10:29 AM
  5. Replies: 9
    Last Post: 01-11-2012, 01:29 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