Solved

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

Posted on 2015-02-19
11
86 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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
 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

773 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