Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    griztkojr is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    30

    Running a Module - Keep getting Errors

    Good morning ALL,



    So i found this wonderful piece of code that helps my report number the pages when the header changes. I tried to run the module but i just keep getting error "The Object doesn't contain the Automation object 'mldPagNum.'. Don't know what else to do. I really don't know if i am Running the module properly (Placing a RunCode Macro from the PageFooter onFormat Section of the report. As the instructions directed I placed a txtbox with the name Me!ctlGrpPages in the Page Footer. The control I want to count is called [DeptDesc]. Here is the code:

    Code:
    '************ Code Start *************' This code was originally written by James H Brooks.
    ' It is not to be altered or distributed,
    ' except as part of an application.
    ' You are free to use it in any application,
    ' provided the copyright notice is left unchanged.
    '
    ' Code Courtesy of
    ' James H Brooks
    '
    Option Compare Database
    Option Explicit
    
    Dim GrpArrayPage(), GrpArrayPages()
    Dim GrpNameCurrent As Variant, GrpNamePrevious As Variant
    Dim GrpPage As Integer, GrpPages As Integer
    
    Private Sub PageFooter_Format(Cancel As Integer, FormatCount As Integer)
    Dim i As Integer
      If Me.Pages = 0 Then    
        ReDim Preserve GrpArrayPage(Me.Page + 1)
        ReDim Preserve GrpArrayPages(Me.Page + 1)    
        GrpNameCurrent = Me!DeptDesc
        If GrpNameCurrent = GrpNamePrevious Then
            GrpArrayPage(Me.Page) = GrpArrayPage(Me.Page - 1) + 1
            GrpPages = GrpArrayPage(Me.Page)
                For i = Me.Page - ((GrpPages) - 1) To Me.Page
                    GrpArrayPages(i) = GrpPages            
                Next i    
        Else
            GrpPage = 1        
            GrpArrayPage(Me.Page) = GrpPage
            GrpArrayPages(Me.Page) = GrpPage    
        End If
      Else
        Me!ctlGrpPages = "Group Page " & GrpArrayPage(Me.Page) & " of " & GrpArrayPages(Me.Page)
      End If
      GrpNamePrevious = GrpNameCurrent
    End Sub '************ Code End *************
    

  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,518
    I don't see any references to that name in the code; are you sure the error comes from this? Can you attach the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Does your report contain the controls [Page] as well as [Pages] that are being referred to in code? As well, you should always indicate which line of code raises an error.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  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,518
    Quote Originally Posted by Micron View Post
    Does your report contain the controls [Page] as well as [Pages] that are being referred to in code?
    Page and Pages are properties of the report.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    You are so correct. I was thinking about the controls that are supposed to contain those numbers.

  6. #6
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716

  7. #7
    griztkojr is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    30
    Quote Originally Posted by orange View Post
    The code comes from http://access.mvps.org/access/reports/rpt0013.htm
    I see no mention of mldPagNum
    I name the module mldPagNum

  8. #8
    griztkojr is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    30
    Quote Originally Posted by Micron View Post
    Does your report contain the controls [Page] as well as [Pages] that are being referred to in code? As well, you should always indicate which line of code raises an error.
    The error just reads "The Object doesn't contain the Automation object 'mldPagNum.'" The control name is Me!ctlGrpPages. Should there be something in the control source?

  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,518
    Quote Originally Posted by griztkojr View Post
    I name the module mldPagNum
    What module? That code should be in the report's module.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    The Me! qualifier should not be part of control name. Me! and Me. are used in VBA as alias for the form or report object name the code is behind. So the textbox name would be ctlGrpPages and VBA would reference the control with Me!ctlGrpPages or Me.ctlGrpPages. I recommend Me. in this case as the dot (.) will provoke intellisense popup tips. Code will actually work without the Me! and Me. qualifiers but is good practice to use. And as Paul points out, the code should be in the report's code module, not a general module.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    griztkojr is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    30
    Quote Originally Posted by pbaldy View Post
    What module? That code should be in the report's module.
    Thank you Paul. How do i get to the report module?

  12. #12
    griztkojr is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    30
    Quote Originally Posted by June7 View Post
    The Me! qualifier should not be part of control name. Me! and Me. are used in VBA as alias for the form or report object name the code is behind. So the textbox name would be ctlGrpPages and VBA would reference the control with Me!ctlGrpPages or Me.ctlGrpPages. I recommend Me. in this case as the dot (.) will provoke intellisense popup tips. Code will actually work without the Me! and Me. qualifiers but is good practice to use. And as Paul points out, the code should be in the report's code module, not a general module.
    Thank you June! i changed the name of the txtbox. From where do i call the VBA? from the control source of ctlGrpPages or from an event?

  13. #13
    griztkojr is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    30
    Quote Originally Posted by griztkojr View Post
    Thank you June! i changed the name of the txtbox. From where do i call the VBA? from the control source of ctlGrpPages or from an event?
    Is this correct?
    Click image for larger version. 

Name:	Capture.PNG 
Views:	19 
Size:	95.3 KB 
ID:	33642

  14. #14
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    At the risk of repeating myself, Me!ctlGrpPages not only will not invoke Intellisense, it will only provide late bound access to the referenced object. If you use Me!ctlGprPages when the reference should be Me!ctlGrpPages it will not be caught when you compile the code. You will only find out when a run time error occurs. While this might be insignificant most of the time because
    a) all of us always use Option Explicit and
    b) Intellisense would prevent an incorrect choice,

    we know that a) is a total lie, and not all objects or methods are exposed by Intellisense even though the vast majority are. Just sayin...

  15. #15
    griztkojr is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    30
    Quote Originally Posted by Micron View Post
    At the risk of repeating myself, Me!ctlGrpPages not only will not invoke Intellisense, it will only provide late bound access to the referenced object. If you use Me!ctlGprPages when the reference should be Me!ctlGrpPages it will not be caught when you compile the code. You will only find out when a run time error occurs. While this might be insignificant most of the time because
    a) all of us always use Option Explicit and
    b) Intellisense would prevent an incorrect choice,

    we know that a) is a total lie, and not all objects or methods are exposed by Intellisense even though the vast majority are. Just sayin...
    Hi Micron. Thank you, I have changed the name of the txtbox to ctlGrpPages and now I changed it in the code. I'ts still not working. The txtbox is blank. I added =[ctlGrpPages] to the control source of the txtbox but it displays #Error.

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

Similar Threads

  1. Running Module with Macro
    By cm-net in forum Macros
    Replies: 2
    Last Post: 01-20-2018, 08:04 AM
  2. Replies: 3
    Last Post: 02-10-2014, 10:21 AM
  3. Replies: 14
    Last Post: 01-31-2012, 09:53 AM
  4. Running a module
    By KevinMCB in forum Modules
    Replies: 2
    Last Post: 03-09-2011, 02:38 PM
  5. Running module from Macro
    By Harley Guy in forum Modules
    Replies: 6
    Last Post: 10-27-2010, 11:05 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