Solved

Suppressing the prefix on a concatenated expression when the underlying control is null, or empty.

Posted on 2015-02-19
11
84 Views
Last Modified: 2015-02-21
I have a control on a form for which the data source is an autonumber field in a table. This number is used as a purchase order number in my database, however my PO numbers are all prefixed with the letters "CC". The control pointing to the data field is hidden in my form, and I have an unbound control which contains the expression ="CC" & [PONumber] so that the number will display on my form as CC12345 for instance.

I have many records for which a PO number has not been assigned yet, and they all display the "CC" with no trailing PO number. Is there a way for me to suppress the "CC" in my expression so that it will only display in the records which actually have PO numbers in them?
0
Comment
Question by:Shooter54
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40620185
Have you tried mid(ponumber,3,100)??
0
 
LVL 11

Accepted Solution

by:
Dany Balian earned 500 total points
ID: 40620188
Or if i misunderstood u in my previous post:
Select iif(isnull(ponumber),'','CC' & ponumber) ....
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40620211
Assuming the [poNumber] is NULL, you can use the + operator rather than the & to concatenate the data.

ControlSource: = "CC" + [poNumber]
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40620214
Just so you understand, when the ampersand (&) is used to concatenate two items, and one of them is NULL, the result is the non-null value:

"A" & NULL = "A"

But when you use the plus sign as the operator, then if either side of the equation is NULL, then the result will be NULL

8 + NULL = NULL
"A" + NULL = NULL

Although technically, you cannot "= NULL"
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40620239
glad I could help.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40620261
ref you personal message:

" I have many records for which a PO number has not been assigned yet,"

I don't understand how this can be an autonumber field as described in your initial statement above and still have PO numbers not yet assigned.  Can you please confirm the data type of PONumber?
0
 

Author Comment

by:Shooter54
ID: 40620264
The data type of the PONumber field in the underlying table is autonumber. This number is created when I select a range of line items and run a query which creates a new record in my PO table, then the PONumber control in my form is updated to include the new PONumber which was just generated. Does that help?
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40620287
Actually, since this is numeric and not a string, Dany's solution is probably the best option:

ControlSource:= iif(isnull(ponumber),'','CC' & ponumber)

you should probably click the Request Assistance hyperlink at the bottom right of your original post and ask the moderator to reopen the question so you can reassign points.

Dale
0
 
LVL 26

Expert Comment

by:Nick67
ID: 40620289
So, you have something like an orders table and a PO table.
This form is based on a query that joins them both.
An order can exist that does not yet have a PO Number
There is an excellent Article about the nice trick @Dale has suggested here
http://www.experts-exchange.com/Database/MS_Access/A_2040-Concatenation-in-Access-Reports-and-Forms.html

Access can do some fun things with null and the concatenator operators + and &.  Read about it.  @harfang explains it better than I ever could.

Now your expression is currently
="CC" & [PONumber]

But you don't want the CC if PONumber is null
So try
=IIF(isnull([PONumber]),"","CC"&[PONumber])
if PONumber is null then  nothing,
else, CC and the PO number

That should do it too
0
 

Author Comment

by:Shooter54
ID: 40620957
=IIF(isnull([PONumber]),"","CC"&[PONumber]) was the solution I was looking for. Thank you for all your help. I have requested assistance so the points can be reassigned.
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40621326
@dale Thanks for ur suggestion!
@shooter glad i could help.. Good luck on ur project
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now