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

    Error on VBA code Compilation

    Wen I try to compile the VBA code in the attached db it crashes on the following error. That is shown in the attached pdf file.



    Something about the procedure does not match the defined function or event. I am not sure what this means.

    I have been changing my VBA code, but I have not been modifying any thing here. How d I fix this?

    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,643
    It's supposed to be:

    Private Sub Form_Undo(Cancel As Integer)
    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
    Okay, but what does cancel as integer mean. The code has been there awhile and now all of a sudden it starts giving an error on compile. I know that in earlier version (say just a few days ago) it gave no such error.

    So why now?

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    I'm not sure. All I know is that adding that stopped the error, and that if you start that event from scratch, that bit is included. Frankly, I think most of your db's have had compile errors, so maybe you just never compiled to that one. If I fix that one, I get another.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Okay, but again to what purpose does the phrase "Cancel as Integer" serve?

    When I added that to the code I got a new error, but an error nonetheless

    The modified db and the pdf file are attached. How to remove this error.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  6. #6
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Wait, I have compiled all of the db in all versions. They did compile as one time. I would always check on it to see if it compiled. That has never been a problem.

    I have pressed the compile code button at the top of the debug dropdown menu with the form in design view and I got no errors. Now I start modifying the code and from out of left filed comes this error.

    That is very confusing.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    Cancel as Integer means the procedure can be canceled, much like the before update event:

    http://www.baldyweb.com/BeforeUpdate.htm

    The next error regarding updateButtons is because that sub is in a form module, not a standard module. You're trying to call it from a different form's module. If you want to call it from multiple places, it should be in a standard module. In this case, since it includes "Me" it can't be. You can either put the full form reference in it, pass the form to be referenced as an argument, or call it as is with:

    Forms!sfrmTelework1.updateButtons

    Thought that's untested.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Okay, I appreciated the response. I have a question however. When it goes to the code and shows an error. How am I supposed to know what form this code is associated with?

    I know how to get VBA code from a form that is easy, so how do I get a form from VBA code?

    Also, this error. I just do not see what I could have done to make this error show up? I can promise I was not adding code anywhere near

    this place where the code errors.

    Any help appreciated. Thanks advance.

    Respectfully,

    Lou Reed

  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,643
    When the compile shows an error (or anytime actually), the object containing the displayed code is in the title bar at the top of the code editor. It will also be highlighted in the project explorer window, though sometimes faintly.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    But how do I know which form (if any) is associated with this code when the error shows up.

    As I said this confusing since I am not messing with any code on the form and when I charge the VBA code and compile - this error is thrown. But an error to what?

    All I can see is the VBA code and the highlight error. I do not even know if it is form code or standard code.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    I'm not sure what you're asking. I can't say why it didn't show up earlier. Presumably you either moved the sub or started calling it from a new location.

    As I said, you can see what object the code is in by looking at the title bar. I searched on updateButtons (Ctl-F) to find the sub, saw it was in a different form module. MZ tools has a search feature that will display all instances of the search text. The built-in Ctl-F only finds them one at a time.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Okay, let me ask this. In the db that I have uploaded in zipped form. If I go to frmEmail. Open up the code associated with that control then go to the debug menu and select compile; it compiles with no errors!

    Now just what is the difference between this db, and the db that I uploaded hours ago that does not compile. It hangs on updateButtons.

    Each have the same db has VBA code associated with frmPersonnel. Yet one compiles and the other does not. That is very confusing to me.


    Also, on a different note or question if the code crashes and shows the VBA source where it crashes then I can find the form (if it is associated with a form) by printing out that module. That is one way.

    However, this seems like an awful lot of trouble just to find the form associated with the code. There must be a easier way. There must be.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    The simple answer is it compiles because you don't have that faulty call in this one. I note several instances where you used the syntax I mentioned:

    Forms!sfrmPropertyPass1.updateButtons

    Maybe I'm not understanding what you mean by finding the form. It's here:
    Attached Thumbnails Attached Thumbnails 2017-07-31_11-09-11.jpg  
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Okay, that was easy to find the form question is answered.

    Now what I want to know is why the older version of the db compiles (I attached to my previous post) and why the latest one does not.
    Please note that in the form in question whose VBA code crashes there is absolutely no difference in the VBA code. The VBA code is the same in both db's. Yetolder one compiles and newer one does not.
    That is the difference. That and only that.

    I have uploaded the two dbs and they are appropriately labeled.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    There was a code difference in the recent db's. In the previous one you had:

    updateButtons

    to call the function from another form, in the latest it was:

    Forms!sfrmPropertyPass1.updateButtons

    The first threw the compile error, the second won't.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Error in VB code
    By Lou_Reed in forum Access
    Replies: 19
    Last Post: 09-21-2016, 08:50 AM
  2. Error in VB code
    By Lou_Reed in forum Access
    Replies: 1
    Last Post: 09-19-2016, 02:47 PM
  3. Replies: 1
    Last Post: 04-10-2015, 07:40 AM
  4. VBA Code Returning Error Run Time Error 3061
    By tgwacker in forum Access
    Replies: 2
    Last Post: 11-24-2013, 11:00 AM
  5. Form compilation failed?
    By pbuck in forum SharePoint
    Replies: 1
    Last Post: 11-26-2012, 02:46 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