Compile throws a “User-defined type not defined” error but does not go to the offending line of code

前端 未结 21 1300
再見小時候
再見小時候 2020-12-14 08:00

Symptoms

This is a symptom specifically when compiling an Excel VBA project. The following error occurs:

User-defined type not defin

21条回答
  •  眼角桃花
    2020-12-14 08:29

    I was able to fix the error by

    1. Completely closing Access
    2. Renaming the database file
    3. Opening the renamed database file in Access.
    4. Accepted various security warnings and prompts.
      • Not only did I choose to Enable Macros, but also accepted to make the renamed database a Trusted Document.
      • The previous file had also been marked as a Trusted Document.
    5. Successfully compile the VBA project without error, no changes to code.
    6. After the successful compile, I was able to close Access again, rename it back to the original filename. I had to reply to the same security prompts, but once I opened the VBA project it still compiled without error.

    A little history of this case and observations:

    • I'm posting this answer because my observed symptoms were a little different than others and/or my solution seems unique.
    • At least during part of the time I experienced the error, my VBA window was showing two extra, "mysterious" projects. Regrettably I did not record the names before I resolved the error. One was something like ACXTOOLS. The modules inside could not be opened.
    • I think the original problem was indeed due to bad code since I had made major changes to a form before attempting to update its module code. But even after fixing the code the error persisted. I knew the code worked, because the form would load and no errors. As the original post states, the “User-defined type not defined” error would appear but it would not go to any offending line of code.
    • Prior to finding this error, I ensured all necessary references were added. I compacted and repaired the database more than once. I closed down Access and reopened the file numerous times between various fix attempts. I removed the suspected offending form, but still got the error. I tried other various steps suggested here and on other forums, but nothing fix the problem.
    • I stumbled upon this fix when I made a backup copy for attempting drastic measures, like deleting one form/module at a time. But upon opening the backup copy, the problem did not reoccur.

提交回复
热议问题