View Full Version : How do I refer to part of a concatenated field?


Irmgard Wesselb
07-12-2006, 02:26 AM
Hi,

I have a mailing label report with a text box (txtAddress) containing:
=[Suburb] & " " & [State]&" "&[PostCode]
which works fine.
Most postcodes in the database have 4 digits, but a few of the addresses only have a 0 (zero) in the Postcode field.
My question: is it possible to suppress this 0 when printing, and if so, how is it done?

The following code, attached to the On Format Event of the detail section, works nicely when the PostCode field is on its own:
---
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If (Me.PostCode = 0) Then
Me.PostCode.Visible = False
Else
Me.PostCode.Visible = True
End If
End Sub
---

However, I would prefer to keep all three fields (Suburb, State, PostCode) concatenated, and the PostCode not showing if it is 0.

Any hint would be greatly appreciated.

Thanks and regards,
Irmgard (Irma) Wesselbaum:confused:

mhartman
07-12-2006, 05:24 AM
Hello:
Update your control with the following:
'
=[Suburb] & " " & [State]&" "& IIf([PostCode]<>0,[PostCode],"")

Regards
Mark

Irmgard Wesselb
07-12-2006, 04:17 PM
Hallo Mark,

Thanks a million for the fast response. I have changed the code as per your suggestion, and it works perfectly!

Regards,

mhartman
07-13-2006, 05:58 PM
Hello: You are most welcome!