Trying to replace text value on a report

Posted on 2012-09-06
Last Modified: 2012-09-06
This is a crazy issue I'm sure but I am trying to replace the value in a text field on a report with another text string if certain criteria exists.  Here is my code but it doesn't work.

    If Me.txtStreet.Value = "original text" Then
        Me.txtStreet.Value = "new text"
    End If

I've tried onprint and onformat both.

Question by:SteveL13
    LVL 61

    Expert Comment

    Your code looks okay.

    What section of the report is txtStreet in?

    Use the Format or the Print event of that specific section.

    In other words if it is in the header, use the Header Format or print events.  If it is in the Detail section, use Detail Format or Print.

    Also some events don't execute in Report View in Access 2007/2010.   If you have been using Report View, try Print Preview instead.
    LVL 61

    Accepted Solution

    Also to make sure that you are not including extraneous spaces, try this:

        If Trim( "" & Me.txtStreet.Value) = "original text" Then
            Me.txtStreet.Value = "new text"
        End If

    Open in new window

    LVL 47

    Expert Comment

    by:Dale Fye (Access MVP)
    No points, just piling on.  

    My guess is that it is the Preview vs Report View issue as mbizup mentions above.
    LVL 61

    Expert Comment

    If that is indeed the case, it will be the third time I've seen it in the past 24 hours. :)

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Dlookup and where condition 3 18
    Show Balance 3 15
    Table Relationships for Linked Tables 2 13
    Greater Than Current Month 2 26
    In the previous article, Using a Critera Form to Filter Records (, the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
    Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
    Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
    In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now