Avatar of beatified
beatifiedFlag for United States of America

asked on 

Query design help Access

I have a query that I am using to combine fields from different tables. It looks like this...

AptNumLetter: '10' & (Left([AptNum],2) & '-' & UCase(Right([tblListAptLetter.AptLetter],1)))

Problem is sometimes there is no AptLetter which means the query returns nothing in that case.

An example would be 1051-A in that case both AptNum (1051) and AptLetter (A) exist so there are no problems.

But in a few cases there is not AptLetter so nothing is returned at all.
I need to fix this so that it return just the AptNum in the cases where there is no AptLetter.

User generated imageHCPV.accdb
Microsoft AccessMicrosoft OfficeDatabasesMicrosoft Applications

Avatar of undefined
Last Comment
beatified
Avatar of Doug
Doug
Flag of United States of America image

Try:
'10' & (Left([AptNum],2) & Nz("-" & UCase(Right([tblListAptLetter.AptLetter],1)),'')

Note that the last two characters before the final paren are two single quotes.
Avatar of beatified
beatified
Flag of United States of America image

ASKER

So it says its missing a ([ or |
i cant figure out where it should go.
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Doug
Doug
Flag of United States of America image

'10' & Left([AptNum],2) & Nz("-" & UCase(Right([tblListAptLetter.AptLetter],1)),'')
Avatar of beatified
beatified
Flag of United States of America image

ASKER

Doug
Unfortunately I couldn't make your solution work

Rey
I don't know where to paste the Sql code?

Might it be better to make this join in the table itself rather than from a query?
I have fixed it for you
HCPV.zip
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Again, your main problem is - as Pat has mentioned before in another question - your table structure. You should always ensure that you can join between fields where the one-side is a straight AutoNumber. If not, you will continue to encounter issues like this.

/gustav
@beatified

see the revised query in this sample db
DB_28921385.accdb
Avatar of beatified
beatified
Flag of United States of America image

ASKER

I'm not sure I have been clear enough to everyone about my issue.

@Rey Obrero
You seem to have nailed it.
I'm just curious how you were able to enter the sql code. was that by right clicking and selecting build?
Avatar of beatified
beatified
Flag of United States of America image

ASKER

Also would it be better to do this as a combined field in a table vs as a query?
Avatar of beatified
beatified
Flag of United States of America image

ASKER

@Rey
Just figured it out right click the tab and select SQL
<I'm just curious how you were able to enter the sql code. was that by right clicking and selecting build? >

create a new query, do not select any table
in the Design icon on the upper LEFT corner, select SQL from the dropdown
you will see a white screen with

SELECT

here is where you will paste the SQL statement that you copied.. you have to overwrite the "SELECT" word shown.
@beatified
don't forget to close the thread.
Avatar of beatified
beatified
Flag of United States of America image

ASKER

I will just one more question on the whole issue of me creating the tables wrong.

@Gustav
Is there a problem with my table structure. From what I can tell @Pat had mentioned that I should not be allowing duplicates under certian circumstances and not in others but rather archive certain records and allow duplicates in the archived table and do not allow duplicates in the non archived area. What he was talking about was a normalization issue. And I completely agree with him on that. It seems like it is this thread you are talking about.
https://www.experts-exchange.com/questions/28920913/Allow-duplicates-under-certain-circumstances-in-access.html

@Rey Please feel free to mention if you see any issues relating to my table structure if you do simply say yes and I will create another question.
it is better that you create another thread for a different topic.
Avatar of beatified
beatified
Flag of United States of America image

ASKER

Ok will do.
Avatar of beatified
beatified
Flag of United States of America image

ASKER

Excellent help and took me through it step by step which I need as a noob.
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo