Darn plus signs in calculated controls/fields... (1 Viewer)

EternalMyrtle

I'm still alive
Local time
Today, 13:38
Joined
May 10, 2013
Messages
533
Why can't I ever get these to work properly? I want to use them to ignore null fields so that I won't get the punctuation but it isn't working.

Here is what I have but the commas still show up:

=IIf([Status]=1,(+[MailBoxOrPOBox]) & (+", "+([CompanyLocID].[Column](2))) & (+" ,"+([CompanyLocID].[Column](3))),"")

is there a better way than trying to use these + signs??

Thank you!!
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:38
Joined
Aug 30, 2003
Messages
36,127
You concatenate the punctuation and the potentially Null field inside parentheses, like

="fixed text" & (", " + PotentiallyNullField)
 

EternalMyrtle

I'm still alive
Local time
Today, 13:38
Joined
May 10, 2013
Messages
533
Could have sworn I tried that but will try again when I return to the office tomorrow. Thanks!
 

EternalMyrtle

I'm still alive
Local time
Today, 13:38
Joined
May 10, 2013
Messages
533
It's still doing it :(

Put in this: =IIf([Status]=1,(+[MailBoxOrPOBox]) & (", "+[CompanyLocID].[Column](2)) & (", "+[CompanyLocID].[Column](3)),"")

and it is showing up like this:

, street address,

(with the first field and the last field being empty)

Why :confused:
 

pr2-eugin

Super Moderator
Local time
Today, 21:38
Joined
Nov 30, 2011
Messages
8,494
I have the same problem. I just thought to myself, screw it and wrote a function. Not the best way, but does what I want ! LOL
Code:
Public Function linearAddress(line1 As Variant, line2 As Variant, line3 As Variant, _
                              Optional line4 As Variant) As String
[COLOR=Green]'**************************************************************
'Code Courtesy of
'      Paul Eugin        March 2013
'   The function JOINS the single 'Atomic' address fields
'               into one Single LINE address.
'       This formatting is used for Mail Merge fields.
'**************************************************************[/COLOR]
    Dim retStr As String
    If Not IsNull(line1) Then retStr = retStr & line1 & ", "
    If Not IsNull(line2) Then retStr = retStr & line2 & ", "
    If Not IsNull(line3) Then retStr = retStr & line3 & ", "
    If Not IsNull(line4) Then retStr = retStr & line4 & ", "

    If retStr = vbNullString Then Exit Function
    linearAddress = Left(retStr, Len(retStr) - 2)
End Function
With the above code.
Code:
? linearAddress(Null, "Westby Road", Null, Null)
Westby Road
? linearAddress(Null, "Westby Road", Null, "BH5 1HA")
Westby Road, BH5 1HA
? linearAddress(12, Null, Null)
12
 

RainLover

VIP From a land downunder
Local time
Tomorrow, 06:38
Joined
Jan 5, 2009
Messages
5,041
Is Column 2 really 2 or should it be 1.

Counting starts at 0.
 

RainLover

VIP From a land downunder
Local time
Tomorrow, 06:38
Joined
Jan 5, 2009
Messages
5,041
I think Column counting starts at 0 in VBA and on forms/query it starts with 1, me thinks !

You may very well be correct. When referring to the Bound Column of a Combo we usually select 1 not 0.

Thank you.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:38
Joined
Aug 30, 2003
Messages
36,127
The column is a property, and doesn't change based on where you're referring to it from. Still zero based on a form.
 

RainLover

VIP From a land downunder
Local time
Tomorrow, 06:38
Joined
Jan 5, 2009
Messages
5,041
Paul

For my clarification.

A Combo on a form has the property of "Column Count" In this situation there is no Zero. It starts at One.

Why do we differ.
 

EternalMyrtle

I'm still alive
Local time
Today, 13:38
Joined
May 10, 2013
Messages
533
Anywhere you are referring to the columns in the form properties it starts at 1 (e.g. bound column or column count).

Anywhere else it starts with 0 (e.g. in code and in calculated controls on a form).
 
Last edited:

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:38
Joined
Aug 30, 2003
Messages
36,127
Paul

For my clarification.

A Combo on a form has the property of "Column Count" In this situation there is no Zero. It starts at One.

Why do we differ.

I'm referring to the Column property itself and saying that whether in VBA code or on a form, the first column will always be zero here:

ComboName.Column(0)

You're referring to a different property, that does indeed start at 1.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:38
Joined
Aug 30, 2003
Messages
36,127
I would be surprised if the single/double quotes was an issue. In a brief test, it didn't matter which I used. That site used singles, but I don't see it saying that they must be used. In any case, glad you have it working.
 

EternalMyrtle

I'm still alive
Local time
Today, 13:38
Joined
May 10, 2013
Messages
533
In a brief test, it didn't matter which I used.

It doesn't seem to matter in queries but in calculated fields it does or at least in did in this case.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:38
Joined
Aug 30, 2003
Messages
36,127
I wasn't saying you were wrong, just that I was surprised. Perhaps it depends on version as I had tested that scenario and it worked fine in a 2007 form:

=[Field1] & (", "+[Field2])
 

EternalMyrtle

I'm still alive
Local time
Today, 13:38
Joined
May 10, 2013
Messages
533
I wasn't saying you were wrong

Don't worry, I didn't take it that way. Hmm, that is odd since I am also using 2007. Sometimes it seems to matter and sometimes it doesn't. I don't get it. Will chalk it up to a quirk.

Just happy I got it working in this instance :)
 

Users who are viewing this thread

Top Bottom