Numbering records on a form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rob Amor
    New Member
    • Sep 2010
    • 30

    Numbering records on a form

    I have a query which returns a list of 5 records at random and have been looking for a way to number these records 1 to 5 simply as a visual aid to users. I used the following code in an unbound text box on my form: =RowNum([Forms]![MyFormName]) and everything worked. Then I used this form as a subform and now get a #Type! error. I thought it would work since the code is contained in the sub form rather than being referred to from the main form but I am clearly missing something. Any advice would be gratefully received.

    Thanks
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    If it's a subform, the form itself is no longer in the forms collection. You will need to access it through the parent form to the subform to the control.

    Comment

    • Rob Amor
      New Member
      • Sep 2010
      • 30

      #3
      Thanks for the reply, I am not sure how to do that. I have tried putting the following code as the control source for the unbound textbox on the subform.
      =RowNum([Forms]![MainFormName]![SubformName]) but am getting the same #type error
      If I add the textbox name =RowNum([Forms]![MainFormName]![SubformName].[textbox] I get a #name? error.
      I appreciate that I am missing something obvious and/or doing something daft but if you could set me right I would be most grateful.
      Thanks

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Do you need to fully qualify the control reference? Can you just not use the textbox name without all the form references?

        Comment

        • Rob Amor
          New Member
          • Sep 2010
          • 30

          #5
          Without using [Forms]![FormName] the RowNum function doesn't work even on a straight form. I have tried various combinations to get it to work but usually when referencing a subform control I do it from the main form and I can't get my head around calling a subform control from the very subform control I am calling. Doesn't feel like it could work, but I am really not much good with VBA so my feeling really doesn't count for very much. Sorry if I am not explaining myself particularly well or if I am misunderstandin g what you are saying.

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            Is this RowNum a custom function? I can't find any reference to it in the Visual Basic 6 documentation.

            Comment

            • Rob Amor
              New Member
              • Sep 2010
              • 30

              #7
              I actually found it on this forum in another post. It suggested using =RowNum([Forms]![MyFormName])in an unbound textbox to number records, and that's about all I know about it. Works a treat until the form becomes a sub form. Certainly if you type rownum into the control source box in the textbox properties it appears as an autocomplete option as a function. Does that shed any light?

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                Still can't find a reference to it. I wonder if it's a part of a third party library. Try using the intellisense to see if there's any documentation on it.

                Comment

                • Rob Amor
                  New Member
                  • Sep 2010
                  • 30

                  #9
                  Had a look and I can't find anything which sheds any light on the problem. Tried searching the internet again and found nothing that helps there either. Maybe it just can't be used in a subform? Maybe time for me to look at an alternative method? Thanks for your Help Rabbit I appreciate your time and input.

                  Comment

                  • Rabbit
                    Recognized Expert MVP
                    • Jan 2007
                    • 12517

                    #10
                    Not a problem, sorry I couldn't be of more help. If you want to try an alternate method, please create a new thread for that so that we can start fresh.

                    Comment

                    Working...