Re: combining multiple address fields into 1 address field
- From: "H" <hal@xxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 28 Nov 2007 19:24:01 -0000
"Stuart McCall" <smccall@xxxxxxxxxxxxxxx> wrote in message
news:fiib13$srj$1$8300dec7@xxxxxxxxxxxxxxxxxxx
I have already created such a query but I really wanted the addresses to
be displayed within a field in just the same way that they would normally
be written; i.e. if all the fields are used an address would appear thus:
Flat 1,
The Smart House
Cred Street
Little Village
Big Town
Countyshire
AB1 2CD
Scotland
Or, if only a few fields contain data it would be displayed so...
Smart House
Cred Street
Big Town
AB1 2CD
Scotland
This would make creating reports for address / phone books or mail merges
much easier as I would only ever had to call 1 field, instead of writing
the expression each time.
I've got as far as creating a a single line of merged text separated by a
comma and space - but I can't see how to insert a carriage return?
Regards Hal
Hal
PMFJI. The way to insert a carriage return is to use the VBA constant
vbCrLf.
This will probably help. Paste the following function into a standard
module:
''' CODE START '''
Public Function AddrLines(ParamArray adLine()) As String
Dim v, r As String
'
For Each v In adLine
If Len(v & "") > 0 Then
r = r & v & vbCrLf
End If
Next
AddrLines = r
End Function
''' CODE END '''
Use it like this:
FullAddress = AddrLines([Field Name 1], [Field Name 2]) etc. etc.
or you can use it in a query:
SELECT AddrLines([Field Name 1], [Field Name 2]) As FullAddress From
whatever
Thanks very much for your help. Being a total beginner I don't clearly
understand how I should create a module or how to write the SELECT query. I
have copied and pasted your code into a module page and saved it named as
"AddrLines".
I'd be most obliged if you could give a worked example using the field names
below:
Address1
Address2
Village
Town
County
Country
Postcode
from a table named: Sheet1
.
- Follow-Ups:
- Re: combining multiple address fields into 1 address field
- From: Stuart McCall
- Re: combining multiple address fields into 1 address field
- References:
- Prev by Date: Re: Call the standard Windows File Open/Save dialog box
- Next by Date: Re: SQL to count the number of nulls in a column
- Previous by thread: Re: combining multiple address fields into 1 address field
- Next by thread: Re: combining multiple address fields into 1 address field
- Index(es):
Relevant Pages
|