VBA with MS Access Reports

Antonio Bassil 40 Reputation points
2025-09-04T07:17:45.8233333+00:00

"Me.TextZone = some value" is not allowed with a report, I want be able to use and change controls.

Developer technologies | Visual Basic for Applications
0 comments No comments
{count} votes

Answer accepted by question author
  1. Adiba Khan 1,600 Reputation points Microsoft External Staff
    2025-09-04T09:58:07.3733333+00:00

    Here are some options that you can try:

    1.      Use control Source expressions

    Instead of setting a value directly , bind the text box to an expression

    =”some value”

    Or to a function

    =MyCystomFunction()

     

    2.      Use the Format or Print Event

    If you want to dynamically set values while report is rendering, you can use VBA inside the report’s On Format event of a section:

    Private Sub Detail_Format(Cancel as Integer, FormatCount as Integer)

                    Me.TextZone.Caption = “some value”

    End Sub

    Note: for labels, use .Caption

                    For unbound text boxes, you can set .Value.

     

    3.      Use an Unbound Text Box

    Create a text box with no control source, then in the event

    Private Sub Details_Format(Cancel As Integer, FormatCount As Integer)

                    Me.TextZone.Value = “Dynamic Value”

    End Sub

     

    4.      Pass Values from a Form to a Report

    If you want to show values from a form:

    Set the text box’s control source to reference the form:

    =[ Forms ]![MyFormName]![MyControlName]

     

    You can also refer the following URLs

    ·         Add a text box control to a form or report - Microsoft Support

    ·         Order of events for database objects - Microsoft Support

    ·         SetValue Macro Action - Microsoft Support

    Hope this helps, Please let me know if you have any other query and if it helps please mark the answer as answered.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.