Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8969875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:39:18+00:00 2026-06-15T17:39:18+00:00

I try to improve a report I made to document databases, by adding a

  • 0

I try to improve a report I made to document databases, by adding a VBA line count to Modules and Forms. The following code works perfectly in a standard module:

Sub test()
    Dim accObj As AccessObject, bwasOpen As Boolean, objName As String
    objName = "Form1"
    Set accObj = CurrentProject.AllForms(objName)
    bwasOpen = accObj.IsLoaded
    If Not bwasOpen Then
        DoCmd.OpenForm objName, acDesign, WindowMode:=acHidden
    End If
    If Forms(objName).HasModule Then
        DoCmd.OpenModule "Form_" & objName
        Debug.Print Modules("Form_" & objName).CountOfLines
    End If
    If Not bwasOpen Then
        DoCmd.Close acForm, objName, acSaveNo
    End If
End Sub

But when I use a similar code in the report itself, I have an error. And since that error is happening in the class module (the report), I feel a bit stuck with debugging. The code in the report:

    Set accObj = CurrentProject.AllForms(objName)
    bwasOpen = accObj.IsLoaded
    If Not bwasOpen Then
        DoCmd.OpenForm objName, acDesign, WindowMode:=acHidden  'Breaks here
    End If
    If Forms(objName).HasModule Then
        DoCmd.OpenModule "Form_" & objName
        GetExtraInfo = Modules("Form_" & objName).CountOfLines
    End If
    If Not bwasOpen Then
        DoCmd.Close acForm, objName, acSaveNo
    End If

The code is called from a report control using =GetExtraInfo(). The whole thing works well, except this new part where I want to return the CountOfLines for Forms.

Update: I have added some error trapping, and it gives error:
2486 – You can’t carry out this action at the present time

The whole db can be downloaded here, its’s only 300 KB. The report is named “rptObjList”.
The “bad” code has been commented out. It is an Access 2003 db.
Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:39:19+00:00Added an answer on June 15, 2026 at 5:39 pm

    Your code opens a form and checks its .HasModule property. And if the form has a module, you open that module to check .CountOfLines. However, you need not open the module to determine its .CountOfLines. And I would try to avoid opening the form, too.

    ? VBE.ActiveVBProject.VBComponents("Form_Form1").CodeModule.CountOfLines
     6 
    

    If you ask for .CountOfLines for a module which doesn’t exist, such as the following, you can trap error #9 (‘Subscript out of range‘) to give you an alternative to checking the .HasModule property:

    ? VBE.ActiveVBProject.VBComponents("bogus").CodeModule.CountOfLines
    

    Or you could check for the code module with a function similar to minimally tested ModuleExists() outlined below.

    Note I’m unsure how helpful my suggestions will be because I struggled to follow your code. Furthermore I unwisely chose to step through the code behind rptObjList and became frustrated by all the unhandled errors when it calls GetDesc() for objects which have no Description property. I just gave up.

    Public Function ModuleExists(ByVal pModule As String, _
            Optional ByVal pProject As String = "") As Boolean
    
        Dim blnReturn As Boolean
        Dim objVBProject As Object
        Dim strMsg As String
    
    On Error GoTo ErrorHandler
    
        If Len(pProject) = 0 Then
            Set objVBProject = VBE.ActiveVBProject
        Else
            Set objVBProject = VBE.VBProjects(pProject)
        End If
        blnReturn = Len(objVBProject.VBComponents(pModule).Name) > 0
    
    ExitHere:
        Set objVBProject = Nothing
        ModuleExists = blnReturn
        Exit Function
    
    ErrorHandler:
        Select Case Err.Number
        Case 9  ' Subscript out of range
            ' no such module; function returns False
        Case Else
            strMsg = "Error " & Err.Number & " (" & Err.Description _
                & ") in procedure ModuleExists"
            MsgBox strMsg
        End Select
        GoTo ExitHere
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try this piece of code - public class WhitespaceTest { public static void main(String[]
Try executing the following in JavaScript: parseInt('01'); //equals 1 parseInt('02'); //equals 2 parseInt('03'); //equals
and again my array of arrays ... I try to improve my app performance
We have a C++ application for which we try to improve performance. We identified
I try to make my code fool-proof, but I've noticed that it takes a
I am reading in an XML file and want to try and improve the
I trying to improve my skills using Try Catch blocks and better error handling.
I try to find addresses in different texts. It works quite well except that
can you help me improve my code... this is all about student information... i'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.