Functions in reports - howto refer to a field?

access Nigeria
  • 13 years ago

    Hi,

    I have an access 2002 report whose RecordSource property is a query, and which contains a textbox whose ControlSource property is a user-defined function like this; 

    =AccountHolder()

    How do I refer to fields in the query from within the AccountHolder() function? Eg.

    Private Function AccoutHolder() as String

          'Code here to return the Name field of the report's query.

    End Function

    I had expected to be able to use Me!Name like on a form, but it raises an error - "... can't find the field xyz"

    Thanks.

  • 12 years ago

    Thats due to the fact that the field doesn't exist on the form. Wink

    Drop the field on the  report, set its Visible property to "no" and you'll then be able to reference it in the code under the report.

    Joe 

  • 12 years ago

    Thanks Joe.

    I found another workaround which is to pass the field value to the function as a parameter eg.

    =AccountHolder([name])

    Thanks again.

  • 12 years ago

    Yip.... that'll work too. Smiley Face

    Glad you got it sorted

    Joe
     

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“If debugging is the process of removing software bugs, then programming must be the process of putting them in.” - Edsger Dijkstra