Results 1 to 8 of 8
  1. #1
    Tegglet is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Sep 2024
    Posts
    12

    7961: Microsoft Access can't find the module 'Form_<Name>' referred to in a macro expression or Visu


    7961: Microsoft Access can't find the module 'Form_<Name>' referred to in a macro expression or Visual Basic code.


    Hi,
    This problem is doing my head in!! The code works for a time then suddenly reports the above error.


    Research has indicated that it could be due to a corruption in the database and suggested the following:

    • Ensure the code has been compiled. This has been done by invoking the first item on the debug menu but has never had any effect.
    • Decompiling the database and recompiling it. This has also been done to no effect.
    • Compact and repair the database, save, close, and reopen. This has been done several times but has never had any effect.
    • Exported the VBA modules, deleted the project, created a new one and imported the VBA modules. This has cured the problem in the past but no longer has any effect.



    I have tried it with the form open in both normal and design mode, hidden and visible.

    In producing the Access file for this post I did a "Save As" on the problem file to sanitise it before posting. This seems to have resolved the problem but it still occurs in the original Access file from which this one was derived. Only changes to Dim statements were made where variables had been declared as public; no code changes have been made.

    I can only assume that some form of bad practice in my code is randomly introducing the problem. I am new to Access VBA programming and have deleted the form and recreated it several times as I explore ways to achieve the results I require. When I delete the form I save and close Access as I have had problems in the past with the forms footprint not being completely erased until the database has been saved, closed and reopened.

    I have to admit to being totally confused and would ask for forbearance if anything doesn't make sense.

    Many thanks in advance.
    Tegglet


    AccessForumPost.zip

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,558
    I would help telling us how to recreate the issue, rather than just chucking a DB up?

    If the Save As for this upload appears to have corrected the problem, I would try that again for the actual database and just rename.?

    Just basic debugging 101.
    Could also try a repair of Office.? It would not hurt.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Tegglet is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Sep 2024
    Posts
    12
    I would help telling us how to recreate the issue, rather than just chucking a DB up?
    If I could recreate the problem I could probably solve it! The problem occurs randomly, Save As corrects sometimes but not others.

    I did not just "chuck a DB up" I went to some lengths to create a small DB the exhibited the problem. The trouble is that in so doing the problem disappeared at the last stage for reasons unknown.

    I was rather hoping that someone with more experience than I have could spot something dodgy in my code, alas that appears to be rather too hopeful!

    I cannot mark this as solved because it isn't but I will not pursue it any further on the forum unless someone posts a helpful response.

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    Looking at the posted DB there really isn't much to go on.

    Your form code only shows a moveSize routine which I would do in the load event.

    your AddGuardFileRefs routine is useless as the references are already checked off in the the DB references. If your trying to insure that other users have those references then using late binding is usually the way to go.
    Your example Db does not call this code.

    As far as your code using VBE extensibility, while I'm familiar with it, I have never seen code where you attempt to concatenate the prefix "Form_" with a form name work. But I could be wrong.

    Code:
    CodeLineCount = Modules("Form_" & SearchForm).CountOfLines + 1                              'This is where it normally fails with runtime error 7961 (Line 30)
    Maybe something like this would work for you.

    Code:
    Sub CountCodeLines(Frm As String)
        Dim objComponent As Object
        Dim strName As String
    
    
        For Each objComponent In Application.VBE.ActiveVBProject.VBComponents
            strName = objComponent.Name
            If strName = "Form_" & Frm Then
                Debug.Print strName, objComponent.CodeModule.CountOfLines
            End If
        Next
    End Sub
    HTH.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #5
    Tegglet is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Sep 2024
    Posts
    12
    Hi Moke123,
    Thank you for your response.

    I have never seen code where you attempt to concatenate the prefix "Form_" with a form name work
    I actually create a form with VBA and name it "GetFileName". For some reason Access adds the prefix "Form_".

    I have incorporated the code you posted but it still resulted in the same error. I have reverted to my original code as it only cycles through the forms rather than all the code modules.


    This is quite bizarre!
    While trying to compose a meaningful response I found that
    Code:
        If Forms(SearchForm).HasModule
    returns True when SearchForm = "GetFileName" but fails when it = "Form_GetFileName" with error "2450: Microsoft Access cannot find the referenced form"

    Conversely
    Code:
    CodeLineCount = Modules("Form_" & SearchForm).CountOfLines + 1
    only works when SearchForm ="Form_GetFileName".

    So far this has worked so I am going to proceed on the basis of the above.
    Regards,
    Tegglet

  6. #6
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    I actually create a form with VBA and name it "GetFileName". For some reason Access adds the prefix "Form_".
    Form_SomeFormName is the class module of the form. You'll notice if you create a form without any code in it, hasmodule will be No, and it wont appear in the VBE.

    fails when it = "Form_GetFileName" with error "2450: Microsoft Access cannot find the referenced form"
    Thats because Form_GetFileName is the module

    If the form is open I believe you can access its module property and get its line count from there.
    Code:
    Forms("GetFileName").Module.CountOfLines
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  7. #7
    Tegglet is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Sep 2024
    Posts
    12
    Hi Moke123,
    Thank you once again for your response.

    Research has indicated that it could be due to a corruption in the database

    It would appear that I am sailing in uncharted waters! Can I take from your comments that my problem has nothing to do with any database corruption but more to do with my lack of understanding of the underlying structure?

    One thing I cannot understand is why the code works for a while then suddenly stops working, or why it sometimes starts working again when I have recreated the project by importing the same VBA code modules into a new database or simply done a "Save As". It's this inconsistency that I find so confusing.

    I would appreciate any help with identifying / finding forms to enable code to access them. I am aware of the existence of form and module collections but I am not sure of the structure and tend to access them using trial and error; this sometimes has unpredictable results! Would you please expand on your last post or point me to a primer that covers the topic.
    Many thanks,
    Tegglet

  8. #8
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    To be honest I don't know what it is your trying to do. Obviously you're trying to get a line count of modules but what for?
    What's the process you're trying to achieve?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. Replies: 3
    Last Post: 05-31-2019, 01:52 PM
  2. Replies: 5
    Last Post: 05-04-2019, 09:02 PM
  3. Replies: 14
    Last Post: 05-03-2019, 01:01 PM
  4. Replies: 3
    Last Post: 10-10-2014, 06:29 PM
  5. Replies: 2
    Last Post: 01-25-2013, 10:23 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