?
Solved

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

Posted on 2015-02-19
11
Medium Priority
?
99 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 total points
ID: 40620188
Or if i misunderstood u in my previous post:
Select iif(isnull(ponumber),'','CC' & ponumber) ....
0
 
LVL 48

Expert Comment

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

ControlSource: = "CC" + [poNumber]
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 48

Expert Comment

by:Dale Fye
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 48

Expert Comment

by:Dale Fye
ID: 40620239
glad I could help.
0
 
LVL 48

Expert Comment

by:Dale Fye
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 48

Expert Comment

by:Dale Fye
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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

719 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