It would help if you showed the all the code, so we know what you are
attempting to do.
I would keep the control bound to the PostalCode field and I would change the
name of the control to txtPostalCode. And in the section's format event
If Len(Me.txtPostalCode) > 5 Then
Me.txtPostalCode.Format = "@@@@@-@@@@"
Me.txtPostalCode.Format = "@@@@@"
Alternative would be to use an IIF statement in the Control Source of
The problem could be that in reports if you don't have a field bound to a
control or used elsewhere (for example, in sorting and grouping) in the report
Access will not return the field when it builds the query for the report and
therefore the field is not available.
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
> I'm using Access via Office XP Pro.
> I am trying to format the Zip Code on the detail line of my report.
> I have tried the following lines of code in both the On Format event and the
> On Print event:
> If len([PostalCode]) > 5 Then
> end if
> if len(Me.PostalCode) > 5 Then
> end if
> In both events and either code, I receive the error message:
> Access can't find the field 'PostalCode' referred to in your expression.
> If I put "PostalCode" as the source of the report's control, then every
> thing works fine, except the zip code is not formatted.
> I tried accessing both Me.PostalCode and [PostalCode] from the immediate
> wndow and receive the same error message.
> I know that I have not mistyped the field because I copied the field name
> from the Source property of the report control. Any idea what is happening?
> I also looked at the query which is driving the report. It shows a field
> call PostalCode and there is data in the field.