Bruce,
Thanks for your post- it was very helpful. And I'm very close...
I created a separate function to determine OptAddress. But I'm still
having
a few spacing issues I'm hoping you can help me with. I seem to be getting
a
blank line for OptAddress. Way back, someone helped me created very
complicated embedded IIf statements. I'd love to streamline if possible.
Here's a snip of the Members query (I left off the function parameters-
functions work correctly):
SELECT nz([NickName],[FirstName]) & " " & [LastName] AS [Member Name],
(SELECT Nz(c2.[NickName],c2.[FirstName]) & " " & c2.[LastName] AS [SONm]
FROM
Contacts c2 WHERE c2.ContactID = Nz(c1.SignificantOtherID,-9999)) AS [SO
Name], DetermineCompanyName(parameters) AS [Company Name],
DetermineAddress(parameters) AS Address, DetermineOptAddress(parameters)
AS
OptAddress, DetermineCity(parameters]) AS City,
DetermineState(parameters])
AS State, DeterminePostalCode(parameters) AS PostalCode...
Then the query to form the labels:
SELECT (IIf(Len(Trim(MK.[Company Name]) & "")=0,IIf(Len(Trim(MK.[SO Name])
&
"")=0,Trim(MK.[Member Name]) & Chr(13) & Chr(10) & Trim(MK.Address) &
Chr(13)
& Chr(10) & (OptAddress + Chr(13) + Chr(10)) & Trim(MK.City & ", " &
UCase(
MK.State) & " " & MK.PostalCode) & Chr(13) & Chr(10),Trim(MK.[Member
Name]) &
Chr(13) & Chr(10) & Trim(MK.[SO Name]) & Chr(13) & Chr(10) &
Trim(MK.Address)
& Chr(13) & Chr(10) & (OptAddress + Chr(13) + Chr(10)) & Trim(MK.City &
",
" & MK.State & " " & MK.PostalCode & " " &MK.Country)),Trim(MK.[Member
Name]) & Chr(13) & Chr(10) & Trim(MK.[Company Name]) & Chr(13) & Chr(10) &
Trim(MK.Address) & Chr(13) & Chr(10) & (OptAddress + Chr(13) + Chr(10)) &
Trim(MK.City & ", " & UCase( MK.State) & " " & MK.PostalCode & " " &
Country))) AS MyLabelContents
FROM [Members] AS MK
Then the label report lists MyLabelContents from above.
Please tell me it doesn't need to be that difficult!
Ultimately I'd like:
ABC Company
Attn: Barbara
1234 Wall St.
Suite 211
Boise, ID 84756
or
John Smith
Sally Smith
123 Terrace Lane
Boise, ID 85746
Or
Sarah Johnson
24 S. Richards
Boise, ID 84756
sorry to dump so much sql on you- just wanted you to see where I stand
now...
thanks!
BruceM said:
You can use vbCrLf in VBA rather than Chr(13) & Chr(10). However, you
may
be overcomplicating this. If you use + rather than & as the
concatenation
operator, if any part of the expression is null the entire expression
evaluates to null. You can use this to your advantage. In a query you
could add a Full Address field. Note that you need to use Chr(13) &
Chr(10)
in this case, since it is SQL rather thatn VBA.
FullAddress: FullName & MailingAddress1 & Chr(13) & Chr(10) & _
(OptAddress1 + Chr(13) + Chr(10)) & _
City & ", " & State & " " & Zip
If OptAddress1 is null, the entire expression within parentheses,
including
Chr(13) + Chr(10), evaluates to null. You can extend the expression to
add
more fields such as MailingAddress2 and OptAddress2. Note that the
underscores are an attempt to get this to read correctly in a newsreader
window, and are not part of the SQL.
In a form or report you could do something similar. The FullAddress text
box is named txtFullAddress.
Me.txtFullAddress = FullName & MailingAddress1 & _
vbCrLf & (OptAddress1 + vbCrLf) & _
City & ", " & State & " " & Zip
Hi,
I'm building mailing labels and I'm wondering how to add a "carriage
return"
so the labels have:
MailingAddress1
OptAddress1 (if optional address: on a separate line; if no optional
address: no blank line).
MailingAddress1
OptAddress1
City, State Zip
Or
MailingAddress1
City, State Zip
Here's the function:
Function DetermineAddress _
(AddressFlag As Variant, MailingAddress1 As Variant,
OptAddress1
As Variant, MailingAddress2 As Variant, OptAddress2 As Variant) As
String
Select Case AddressFlag
Case 1
DetermineAddress = MailingAddress1 + " " + Nz(OptAddress1,
"")
...
Here's the label query snip:
DetermineAddress([AddressFlag],[MailingAddress1],[OptAddress1],[MailingAddress2],[OptAddress2])
AS Address
Here's the label formatting snip:
& Trim(LK.Address) & Chr(13) & Chr(10)
But by this time, I've concatenated Address into one line. I'd
appreciate
your suggestions. Thanks.