Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Microsoft question regarding IIf statement or a better solution

I am working on a report that needs international addresses that are correct to the country’s standard to where the mail is going.

Some countries want the postal code before the City, others don’t and some have regions/states, while others dont.

I have this expression:
=IIf(Eval([country] In ("Italy","Czech Republic","Argentina","Austria","Belgium","China")),([zip] & " " & [city]),([city] & ", " & [region] & " " & [zip]))

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I might have another 5-10 countries to put in.. Is there a better way of handling this in expression builder with like a lookup or something? I did not know if there is a limit to how long a expression can be in Access.

Thanks for any input.

It is working right now, but looking for a better solution.

>Solution :

Consider creating a function. This function accepts Country, City, Region, and Zip as parameters. Within the function use a SELECT CASE statement on Country and return the appropriate formatted string for each case.

In a MODULE add

Public Function CityZip(strCountry As String, strCity As String, strZip As String, strRegion) As String

  Select Case strCountry
  Case "Italy", "Czech Republic", "Argentina", "Austria", "Belgium", "China"
     CityZip = strZip & " " & strCity
  Case Else
     CityZip = strCity & " " & strRegion & " " & strZip
  End Select

End Function
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading