Share via


VBA Function to encode a URL query string?

Question

Tuesday, August 18, 2015 9:05 PM

Is there a builtin VBA function that encodes a URL query string (replacing special characters with encoded equivalents)? Failing this, is there one posted anywhere that I can use? I hate to have to reinvent the wheel. Thanks. 

All replies (5)

Tuesday, August 18, 2015 9:43 PM ✅Answered

I came up with my own solution that just changed the characters I needed:

SQL = "SELECT TBL_CD, TBL_DESC FROM SYSUSR.GEN_TBL_2_W_D WHERE TBL_TYP  = 'PRTYP' AND STA_CD = 'A' AND TBL_CD IS NOT NULL"
   ' Encode URL special characters
   SQL = Replace(SQL, " ", "%20")
   SQL = Replace(SQL, "'", "%27")
   SQL = Replace(SQL, ",", "%2C")
   SQL = Replace(SQL, "_", "%5F")
   SQL = Replace(SQL, "=", "%3D")
   MsgBox SQL
   URL = "http://159.87.70.66:3502/MSCRFILE/AES_AZ_EXECSQL?sqlName=ProviderTypes&sqlStr=" & SQL


Tuesday, August 18, 2015 9:12 PM | 1 vote

Hi. I just did a quick search and saw this one. Not sure if that will be enough for you. I'll post back if I find anything else. Hope that helps...


Tuesday, August 18, 2015 9:12 PM

Is there a builtin VBA function that encodes a URL query string (replacing special characters with encoded equivalents)?

Post data examples of what you are trying to do (Raw data --  End process).

Build a little, test a little


Tuesday, August 18, 2015 9:26 PM

This page will explain:

http://www.w3schools.com/tags/ref_urlencode.asp


Tuesday, August 18, 2015 10:26 PM

Good work! Congratulations!