1

Is there a way to convert Unicode string data from an Access table into UTF-8 format? The reason I ask is because I want to use the ActiveX web browser control with Greek HTTP string.

Edit:

Just to add the function returning the URL String

Dim tempsql As String
Dim rs As DAO.Recordset
Dim webAddress As String

tempsql = "Select real_address from propertyData"
Set rs = CurrentDb.OpenRecordset(tempsql)


webAddress = "http://maps.googleapis.com/maps/api/staticmap?"
webAddress = webAddress & "center=Athens,Greece&zoom=myzoom&size=800x1200&"

Do While Not rs.EOF
webAddress = webAddress & "markers=color:red%7Clabel: %7C" & rs.Fields(0).Value & "&"
rs.MoveNext
Loop
webAddress = webAddress & "sensor=false"
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
  • Try constructing your URL string using the normal Unicode characters from the Access table and passing that URL string to the `ControlSource` property of the Web Browser control. I just tried it and it worked fine for me (with Greek characters), suggesting that the Web Browser control may do the required encoding for you. – Gord Thompson Dec 07 '15 at 16:43
  • Please explain what are the 'normal Unicode characters from the Access table'? I am currently constructing the url text by inserting text from a table using vba code using dao elements (not direct sql code). – Mike Perakis Dec 08 '15 at 00:29
  • I also have to mention that I am using the .Navigate property of the ActiveX component, not the controlSource property of the standard webbrowser object of ms Access... – Mike Perakis Dec 08 '15 at 00:37
  • I have placed a new standard WebBrowser Control (Not the ActiveX component) on the form and executed: WebBrowser224.ControlSource = "=(""" & mapForAll(13) & """)" Where mapForAll(13) is the function returning the whole http string. No luck – Mike Perakis Dec 08 '15 at 00:50

1 Answers1

3

Here's what works for me in Access 2010 with a form that includes the stock Web Browser control

WebBrowserControl.png

With a table named [GreekWords]

id  word
--  ----
 1  Ώπα

a button on the form opens the Greek Wikipedia page for that word with this code:

Option Compare Database
Option Explicit

Private Sub Command1_Click()
    Dim word As String, url As String
    word = DLookup("word", "GreekWords", "id=1")
    url = "http://en.wikipedia.org/wiki/el:" & word
    Me.WebBrowser0.ControlSource = "=""" & url & """"
End Sub

Here is the HTTP request as captured by Wireshark, showing that the Unicode characters in the URL are indeed automatically encoded as UTF-8 and then percent-escaped (%CE%8F%CF%80%CE%B1):

Wireshark.png

Edit re: question update

It appears that the Web Browser control behaves differently when there is a querystring involved. When I tried

Option Compare Database
Option Explicit

Private Sub Command1_Click()
    Dim word As String, url As String
    word = DLookup("word", "GreekWords", "id=1")
    url = "http://localhost:8080/echo.php?arg=test%7C" & word
    Me.WebBrowser0.ControlSource = "=""" & url & """"
End Sub

the HTTP request sent was

GET /echo.php?arg=test%7C?pa HTTP/1.1\r\n

so it looks like we do need to do our own encoding if the Unicode characters appear in the querystring:

Option Compare Database
Option Explicit

Private Sub Command1_Click()
    Dim word As String, url As String
    word = DLookup("word", "GreekWords", "id=1")

    ' URL encoding, ref: http://stackoverflow.com/a/28923996/2144390
    Dim ScriptEngine As Object, encodedWord As String
    Set ScriptEngine = CreateObject("scriptcontrol")
    ScriptEngine.Language = "JScript"
    encodedWord = ScriptEngine.Run("encodeURIComponent", word)
    Set ScriptEngine = Nothing

    url = "http://localhost:8080/echo.php?arg=test%7C" & encodedWord
    Me.WebBrowser0.ControlSource = "=""" & url & """"
End Sub

which sends

GET /echo.php?arg=test%7C%CE%8F%CF%80%CE%B1 HTTP/1.1\r\n
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
  • Well we have exactly the same principle with the difference that your 'url' string comes from a DLookup function and mine comes from a 'url construction' function... – Mike Perakis Dec 08 '15 at 08:39
  • Yes, this one worked ! Of course I am having another problem now... The URL created is too long (more than 2048 bytes)... Any Ideas on how to shrink a really long URL ? – Mike Perakis Dec 09 '15 at 00:28