Question

I'm opening a recordset in VBA which has special characters like Check Marks, bullet points, and other things pulled in from Word. The process is going to add the fields back into word bookmarks, but I'm having an issue with fomatting. I'm pulling from rich text memo fields, and even though the characters show up in the table, they don't show up when I mouse over the values in the code. I'm getting the question mark in a box in the code, and when it is exported out into my word document. The bullet points appear in both the mouseover value in the code and the export into word, but the other characters change when I open the recordset in code.

I assume it is some sort of UTF conversion problem, but I don't know why it would be fine in the table but mess up when I use the DAO.Database.OpenRecordset. These are symbols native to Word, and appear in access tables. I seem to lose everything once I put it into a DAO.recordset.

I've tried creating a querydef and opening that, querying the table in OpenRecordset, just opening the table directly in OpenRecordset, and none of them are working.

Was it helpful?

Solution

Don't be misled by the mouseover behaviour in the VBA editor. It simply cannot display multi-byte characters (i.e., essentially anything outside of the Windows "ANSI" character set). DAO can indeed manipulate multi-byte (e.g., Unicode) characters, but the VBA editor cannot display them in tooltip text, or in the Immediate window, or in the Watch window.

To illustrate, for the following test data in an Access table named [vocabulary]

ID  word    language  english_equiv
--  ------  --------  -------------
3   γιορτή  Greek     feast 

The following code

Option Compare Database
Option Explicit

Sub rsTest()
    Dim cdb As DAO.Database, rst As DAO.Recordset
    Dim strm As ADODB.Stream
    Set cdb = CurrentDb
    Set rst = cdb.OpenRecordset("SELECT word FROM vocabulary WHERE ID=3", dbOpenSnapshot)
    Debug.Print rst(0).Value
    Set strm = New ADODB.Stream
    strm.Type = adTypeText
    strm.Charset = "utf-8"
    strm.Open
    strm.WriteText rst(0).Value
    strm.SaveToFile "C:\Users\Gord\Desktop\foo.txt"
End Sub

displays the following in the VBA editor's Immediate window

????t?

but the resulting text file does contain the correct (Greek) characters

text.png

So don't fret over the ? characters in the VBA editor display and concentrate on what actually ends up in your Word document.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top