Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2015-02-19
11
Medium Priority
?
100 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 2000 total points
ID: 40620188
Or if i misunderstood u in my previous post:
Select iif(isnull(ponumber),'','CC' & ponumber) ....
0
 
LVL 49

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
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 49

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 49

Expert Comment

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

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 49

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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Suggested Courses

972 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