Results 1 to 11 of 11
  1. #1
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664

    Cannot find Converted Macro VBA code

    In the attached zipped db file when I open frmEditProject it says that it cannot find


    formHeading.

    This one of many forms that says this exact message when I open it. There are several others.

    I translated the macro formHeading to VBA code and it is in the Modules section of the navigation pane.

    It should be able to find fromHeading there.

    I am not sure why it is not finding the VBA code in the Modules section as Convert Macro FormHeading. It is there, but it is not found.

    How do I fix this? As I said it is also occurring other form openings such as EditPropass, EditTelework, etc.

    It seem the converted macro to VBA code should be found.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed.
    Attached Files Attached Files

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    When you reference a function in an event like that, a) it has to start with "=" and b) you have to include the parentheses "()" to indicate it is a function.

    change the On Open event setting in the form to: =FormHeading()

    That will be the case for all the forms giving you that error.

  3. #3
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Okay, thanks for your help.

    Respectfully,

    Lou Reed

  4. #4
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Well, that works. Now if I open frmAttendance (or fmrAddmeeting) and close it - I get a type mismatch. I am not sure where, but I believe it occurs when I call the function addMissingRows.

    The same zipped db that I uploaded yesterday contains this error.

    What line is causing the Type Mismatch error and how do I fix it?

    Any help appreciated.

    Respectfully,

    Lou Reed

  5. #5
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    These two screenshots illustrate my point. The original code called macros. It worked.The new had macro eliminated and the VBA code called the functions directly.

    That is failing. Why is it not working.? I believe that I followed the rules. These macros have arguments so I added them when I switched to VBA code.

    Yet they do not work.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Thumbnails Attached Thumbnails Capture2.GIF   Capture1.GIF  

  6. #6
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I really need an answer to this last post It is holding me up. I rewrote the VBA code to take out the macro no RunMacro's. The macros are now functions, some with arguments, most without functions.

    I just call the functions directly in the VBA code. I think that I used the correct syntax when I did this, but I cannot be sure. Please tell me the syntax is correct. I am using the new syntax now but I am getting a type mismatch. That should not happened.

    How do I fix this?

    Thanks in advance.

    Respectfully,

    Lou Reed

  7. #7
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    These macros have arguments so I added them when I switched to VBA code.
    That's where you went wrong. The first lines of those functions are:

    Function FormHeading()
    and
    Function addMissingRows()

    Neither of them has arguments (did you not look at them?), so when you call them with an argument, you get an error. Just take the argument off the function calls.

    PS - I never use macros, so I can't say why the original macros you converted use arguments.

  8. #8
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I was told by someone here that I can call a function with no arguments just by using the name of the function.

    DoCmd.RunMacro "FormaHeading"

    is now just

    FormHeading

    it make no sense to call a macro in VBA that then calls a function. So I just called the function directly.

    Is this okay?

    I posted a much longer answer, but it did not make to post. It must have been deleted.

    I was told this about 10 days ago. I can provide a reference if required.

    Respectfully,

    Lou Reed

    PS
    Here is the reference on how to call functions in VBA code that have no arguments.

    https://www.accessforums.net/showthr...highlight=Reed

    Now I think that I se the point the arguments for the expression

    DoCmd.RunMacro "FormaHeading" , ,""

    They are macro arguments and should not affect the calling of the VBA function. Still what do I do with them?

    It is very confusing when they add something like ", ," to the end of a macro call.

    Again, what do I do with them?

  9. #9
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I need an answer to this question in Post #8. As I said before

    DoCmd.RunMacro"FormHeading" can be rewritten to eliminate the "VBA calling a macro calling a VBA" to call the VBA function directly like this FormHeading.


    in the case of the call the macro with arguments

    DoCmd.RunMacro"FormHeading", ,"" can be rewritten as what? The called macro has arguments, but the called function has no arguments.

    So how is this rewritten? Is it like this: FormHeading ?

    So what do we do with the ",,"? Ignore it?

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

  10. #10
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    So how is this rewritten? Is it like this: FormHeading
    ?

    Yes. Functions without arguments are not usually referenced with (). But see post #2 in this thread.
    So what do we do with the ",,"? Ignore it?
    In this case, yes. Your best approach when converting a macro is to look at the resulting VBA function and go from there. As I have said, I don't use macros, but I think that maybe whoever wrote those two macros in the first place didn't do it right. But that's only a guess.

  11. #11
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Again, I just want to confirm this before I put this argument to bed. I just write

    DoCmd.RunMacro "FormHeading"

    and

    DoCmd.RunMacro "FormHeading",,""

    the same way?

    This way

    Call FormHeading()

    These are written the same way? Again in the second example the expression, ",,"", was put there for reason. Now we just ignore it?

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

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

Similar Threads

  1. Auto run converted Macro
    By steven7 in forum Macros
    Replies: 3
    Last Post: 06-09-2016, 11:26 AM
  2. Find and Replace in macro code
    By chris.emery in forum Macros
    Replies: 1
    Last Post: 10-11-2015, 08:12 AM
  3. Code/Macro for Find and Replace with Checkbox
    By mortonsafari in forum Access
    Replies: 3
    Last Post: 07-21-2015, 06:51 PM
  4. Using macro converted to VBA in other functions
    By gaker10 in forum Programming
    Replies: 4
    Last Post: 08-19-2014, 07:44 AM
  5. Converted macro to VBA not working
    By gemadan96 in forum Forms
    Replies: 5
    Last Post: 06-04-2014, 10:36 AM

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