none
VBA Function to encode a URL query string? RRS feed

  • Question

  • 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. 
    Tuesday, August 18, 2015 9:05 PM

Answers

  • 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:43 PM

All replies