Solved #Error on shortening postcode if no postcode is present (1 Viewer)

Number11

Member
Local time
Today, 07:31
Joined
Jan 29, 2020
Messages
607
So i have this to shorted the postcode, which is working as long as a postcode is provided within the field, how can i get around so i dont get the #ERROR would like it just to be left blank? please?

ShortPostcode: Left([PostCode],1) & IIf(Asc(Mid([PostCode],2,1))>=65,Mid([PostCode],2,1),"")
 

ebs17

Well-known member
Local time
Today, 08:31
Joined
Feb 7, 2020
Messages
1,949
While SQL and thus queries can brilliantly handle NULL content, this is not always the case when using VBA functions.
In your example, Asc has a problem with NULL. With Nz you can set a replacement value, like ...
Code:
... & IIf(Asc(Mid([PostCode], 2, 1), 0) >= 65, ...
 

cheekybuddha

AWF VIP
Local time
Today, 07:31
Joined
Jul 21, 2014
Messages
2,280
Try:
Code:
ShortPostcode: IIf(Len(Postcode & '') >0, Left([PostCode],1) & IIf(Asc(Mid([PostCode],2,1))>=65,Mid([PostCode],2,1),""),  '')
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:31
Joined
May 7, 2009
Messages
19,247
you can also add two spaces to your Postcode field:

Code:
ShortPostcode: Trim(Left([PostCode] & Space(2),1) & IIf(Asc(Mid([PostCode] & Space(2),2,1))>=65,Mid([PostCode] & Space(2),2,1),""))
 

Users who are viewing this thread

Top Bottom