Solved

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

Posted on 2015-02-19
11
81 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

705 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

20 Experts available now in Live!

Get 1:1 Help Now