Concatenate number and symbol (2 Viewers)

Gismo

Registered User.
Local time
Today, 21:47
Joined
Jun 12, 2017
Messages
1,298
Hi all,

Hope you are well

I tried to concatenate with + if there are no data but getting errors

Limit 1 and Unit 1 will always have data
Limit 2 and Unit 2 might not always have data

If Limit 2 has no data, I don't want to show the "/"

Please could you assist?

Limit: [Limit 1] & " " & [Unit 1] & " / " & [Limit 2] & " " & [Unit 2]
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:47
Joined
May 7, 2009
Messages
19,245
Limit: [Limit 1] & " " & [Unit 1] & (" / " + [Limit 2] + " " + [Unit 2])
 

Gismo

Registered User.
Local time
Today, 21:47
Joined
Jun 12, 2017
Messages
1,298
Limit: [Limit 1] & " " & [Unit 1] & (" / " + [Limit 2] + " " + [Unit 2])
This is what I tried
I get an #Error when there is no data in Limit 2

1692269138989.png
 

Minty

AWF VIP
Local time
Today, 19:47
Joined
Jul 26, 2013
Messages
10,371
No, you appear to be getting an error when there IS data in limit 2.

Copy and paste exactly what is in YOUR query - not what arnelgp wrote.
 

Gismo

Registered User.
Local time
Today, 21:47
Joined
Jun 12, 2017
Messages
1,298
No, you appear to be getting an error when there IS data in limit 2.

Copy and paste exactly what is in YOUR query - not what arnelgp wrote.
With my code, this is what I get
I used the + before and also got the error
Limit: [Limit 1] & " " & [Unit 1] & " / " & [Limit 2] & " " & [Unit 2]

1692271821816.png
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:47
Joined
Sep 21, 2011
Messages
14,310
No, That code gives the same error

Refer to post #3
From the immediate window. on what arnelgp supplied
Code:
limit1="600"
unit1="FH"
Limit2=Null
Unit2="M"
? Limit1 & " " & Unit1 & " / " + Limit2 + " " + Unit2
600 FH

Limit2=""
? Limit1 & " " & Unit1 & " / " + Limit2 + " " + Unit2
600 FH /  M

slight amendment
Code:
limit1="600"
unit1="FH"
Limit2=Null
Unit2="M"
? Limit1 & " " & Unit1 & " / " + Limit2 & " " & Unit2
600 FH /  M

Limit2=""
? Limit1 & " " & Unit1 & " / " + Limit2 & " " & Unit2
600 FH /  M
If any are numeric, you need to convert to string with Cstr()
 

Minty

AWF VIP
Local time
Today, 19:47
Joined
Jul 26, 2013
Messages
10,371
@Gasman It doesn't like adding the numeric value when it is null.
Look at the sample attached.
Expr3: CStr([Limit2])
1692274174786.png
 

Attachments

  • Test1.accdb
    608 KB · Views: 54

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:47
Joined
May 7, 2009
Messages
19,245
can you change it to:
Code:
SELECT [Limit 1] & " " & [Unit 1] & iif(trim(" / " & [Limit 2] & " " & [Unit 2])="/",""," / " & [Limit 2] & " " & [Unit 2])  AS Limit, Table1.[Limit 1], Table1.[Unit 1], Table1.[Limit 2], Table1.[Unit 2]
FROM Table1;

replace Table1 with the name of your table.


limits.png



Code:
Limit: [Limit 1] & " " & [Unit 1] & IIf(Trim(" / " & [Limit 2] & " " & [Unit 2])="/",""," / " & [Limit 2] & " " & [Unit 2])
 

Minty

AWF VIP
Local time
Today, 19:47
Joined
Jul 26, 2013
Messages
10,371
@Gasman - Nope because then the + doesn't work because it's no longer null leaving the / behind.
 

Gismo

Registered User.
Local time
Today, 21:47
Joined
Jun 12, 2017
Messages
1,298
can you change it to:
Code:
SELECT [Limit 1] & " " & [Unit 1] & iif(trim(" / " & [Limit 2] & " " & [Unit 2])="/",""," / " & [Limit 2] & " " & [Unit 2])  AS Limit, Table1.[Limit 1], Table1.[Unit 1], Table1.[Limit 2], Table1.[Unit 2]
FROM Table1;

replace Table1 with the name of your table.


View attachment 109483


Code:
Limit: [Limit 1] & " " & [Unit 1] & IIf(Trim(" / " & [Limit 2] & " " & [Unit 2])="/",""," / " & [Limit 2] & " " & [Unit 2])
Thank you so much
Looks good
 

Users who are viewing this thread

Top Bottom