Access field from Report Recordset

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    Access field from Report Recordset

    I have a field tx_Value which I want to use in some Detail_Format event.

    However if I try using:
    Code:
    Me.tx_Value
    I get an error msg "Method or Data Menber not found"

    If I try either of these
    Code:
    me.recordset.tx_Value
    me.recordset!tx_Value
    I simply get a printed "Error" in my report, no error msg.

    I have a textbox in my report with controlsource=s trTenderDoc()
    Code:
    Private Function strTenderDoc() As String
        strTenderDoc = Me.Recordset!tx_Value
    End Function
    (The "real" code I want to run is a bit more complicated, but im stumped at accessing the value of tx_Value, so ive simplified the problem to look at that.

    Now, I know I can access the tx_Value if I were to make a textbox tb_Value, with the controlsource tx_Value, and just tb_Value in my code. However, I would prefer not to have to make 4 hidden textboxes if it could be avoided.

    So how can I access a field from my recordset within the detail_Format, without adding it as a textbox?
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    Hmm, why so much effort. I normally place the coding needed in the report query and use the result in my detail section.

    Nic;o)

    Comment

    • TheSmileyCoder
      Recognized Expert Moderator Top Contributor
      • Dec 2009
      • 2322

      #3
      Because sometimes the formatting of an item might depend on the value given in type.

      For instance:
      Code:
      If ID_Type="Header" then
        Code goes here.
      end if

      Comment

      • nico5038
        Recognized Expert Specialist
        • Nov 2006
        • 3080

        #4
        Then I would use the Conditional formatting and select "Expression " for the field that needs the formatting.
        Thus you can refer to recordset fields not placed in the detail section, like:
        Code:
        [Type] <> 5
        Nic;o)

        Comment

        • TheSmileyCoder
          Recognized Expert Moderator Top Contributor
          • Dec 2009
          • 2322

          #5
          I do alot more then just conditional formatting though. Based on several parameters, I may choose to indent (move the field a bit to right) or sometimes move it downwards a bit. I also check the length of the field, as well as perform a calculation on the estimated length (height really) of the next two fields. If the current item is a header, and I estimate the next item can not be made to fit on the this page, I move the header to the next page. In that way, I dont have Headers at the bottom of hte page, with no text beneath them.


          The question still remains, can I access the values in the reports recordset, without adding a textbox?

          Comment

          • topher23
            Recognized Expert New Member
            • Oct 2008
            • 234

            #6
            I'm pretty sure I've done this before by wrapping the field name in brackets, like

            Code:
            If [tx_Value]=MyValue Then 'do something
            but then again, that could just be the brain tumor playing tricks on me...

            Comment

            • TheSmileyCoder
              Recognized Expert Moderator Top Contributor
              • Dec 2009
              • 2322

              #7
              No luck. Thanks for the try though. :)

              Comment

              • nico5038
                Recognized Expert Specialist
                • Nov 2006
                • 3080

                #8
                Hmm, much work in rebuilding MS Word functions :-)

                Guess you already proved that a direct reference doesn't work, so another way would be to get the needed data by processing the report's recordset directly.
                A Dlookup or faster recordset processing (using the unique id of the detail row) is an option, but it will slow down the process.

                Guess the hidden fields option is the easy (and fastest) way out.

                When I needed some "heavy formatting" in the past I switched to MS Word automation.

                Nic;o)

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32656

                  #9
                  Originally posted by TheSmileyOne
                  So how can I access a field from my recordset within the detail_Format, without adding it as a textbox?
                  I think you have your answer now, but in case it's not clear, I believe that the answer is a simple No.

                  Fields in the underlying (or bound) recordset of the form or report are not accessible directly. The usual method to get around this is the one you've already found, hidden controls, which is somewhat clumsy I agree.

                  Comment

                  Working...