Report Cannot Access Class Object

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3653

    Report Cannot Access Class Object

    Very Strange one here...........

    I've created a Class Object, named ManagementLevel .

    When I open my DB, it established a new object of that type and assigns various values as needed. I can use this object absolutely anywhere in my DB, as I have made this object Public.

    (HIGHLY simplified, but just for demonstration)
    Code:
    Option Compare Database
    Option Explicit
    
    Public ML   As New ManagementLevel
    
    Public Sub _
        SetDBDefaults()
    On Error GoTo EH
    
        ML.Images = "\\SERVER\FOLDER\IMAGES\"
    
        Exit Sub
    EH:
        MsgBox "You big dummy!" 
        Exit Sub
    End Sub
    However, when I have a report, I am unable to use that object:

    Code:
    Private Sub _
        Detail_Format( _
            Cancel As Integer, _
            FormatCount As Integer)
    
        Me.imgMLShield.Picture = ML.Images & "MLWhite.jpg"
    
    End Sub
    Compiling produces the error: "Method or data member not found"--even though everywhere else in the DB that has this code, all is fine. In fact, the VBA Editor does not even bring up the possible list of values, either.

    After some experimentation , I have determined that at as long as I don't have a Record Source for the Report, all is well. However, as soon as I assign a Record Source, it throws the error.

    Any ideas?

    Thanks for the hepp!
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    Hi Twinny.

    If imgMLShield is a bound Image Control then trying to change the value during that event will cause it to complain. A Report doesn't allow changing of data.

    I don't exactly know how it manages the Picture property but it seems to treat it almost like it's somehow linked to the data. The PictureType property may also be worth playing with.

    All that said, I have an example that works using the ReportHeader_Fo rmat() Event Procedure and that works perfectly well for me (Access 2003) with an Image Control. I did notice that in 2003 there is no ControlSource property, thus no concept of a Bound Control as such. In 2010 there is so that may explain the difference in behaviour.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      I guess what I should have started with is to suggest you first determine if the issue is related to the Class Object or where in the code it is trying to make changes to the Control.

      Try :
      Code:
      Debug.Print ML.Images
      ... before the line that crashes and see what you get.

      Comment

      • twinnyfo
        Recognized Expert Moderator Specialist
        • Nov 2011
        • 3653

        #4
        It really is the strangest thing. The only thing I am changing is whether or not the report has a Record Source. If not, all works well. If so, it doesn't even recognize the existence of that Class Object.

        This only seems to affect my reports.

        Comment

        • lewish95
          New Member
          • Mar 2020
          • 33

          #5
          Access checks to see whether the referenced file is currently loaded in memory.
          If the file is not loaded in memory, Access tries to verify that the RefLibPaths registry key exists. If the key exists, Access looks for a named value that has the same name as the reference. If there is a match, Access loads the reference from the path that the named value points to.
          Access then searches for the referenced file in the following locations, in this order:
          The Application folder (the location of the Msaccess.exe file).
          The current folder that you see if you click Open on the File menu.
          The Windows or Winnt folder where the operating system files are running.
          The System folder under the Windows or Winnt folder.
          The folders in the PATH environment variable that are directly accessible by the operating system.
          If Access cannot find the file, a reference error occurs.

          Comment

          • twinnyfo
            Recognized Expert Moderator Specialist
            • Nov 2011
            • 3653

            #6
            lewish95,

            I'm not sure your response had anything to do with the use of Class objects. The issue is that the Report won't even recognize the existence of the class object when I assign a record source to the report.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32633

              #7
              Did you try the Debug.Print of ML.Images Twinny? If so what did you see?

              Comment

              • twinnyfo
                Recognized Expert Moderator Specialist
                • Nov 2011
                • 3653

                #8
                Neo,

                It can’t get there. Again, If my report is unbound (no record source), if I put code in there and start typing ML. the VBA editor gives me a choice of my properties. However, as soon as my report is bound to a record source, I do the same thing, and I just get Value. The code won’t compile, either, as it can’t recognize the variable/statement.

                I can use that class object anywhere else freely, just not with a bound report. I’ve even tried beginning with a brand new Report object, with no success.

                I did run across this again with another form; but when I created a new form from scratch, it allowed me to use the class object.

                This is ALMOST as strange as the form I had once that didn’t allow me to use the Len() function in its code.

                Comment

                • Rabbit
                  Recognized Expert MVP
                  • Jan 2007
                  • 12517

                  #9
                  The only thing that comes to mind is if the record source has a property, method, or field with the same name.

                  Comment

                  • twinnyfo
                    Recognized Expert Moderator Specialist
                    • Nov 2011
                    • 3653

                    #10
                    BINGO!

                    I knew it had to be something simple! I just made a few changes to the underlying Query and recreated the Report (to shake a hidden connection to the old ML reference) and all is well!

                    Thanks so much for the hepp!

                    Comment

                    • Rabbit
                      Recognized Expert MVP
                      • Jan 2007
                      • 12517

                      #11
                      No problem! :)

                      Comment

                      Working...