外文字符显示为?????在2003年VBA,如何设置UTF-8? [英] Foreign characters show up as ????? in VBA 2003, how to set up UTF-8?

查看:414
本文介绍了外文字符显示为?????在2003年VBA,如何设置UTF-8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库,Access 2003中,需要与外国语言文字工作。字符显示精细的表。然而,当VBA尝试读取这些,就不可能做到这一点。

I have a Database in Access 2003 that needs to work with foreign language characters. The characters show up fine in the table. However, when VBA tries to read them it cannot do it.

作为一个例子,从cf_Answer显示器列ANSWER_TEXT:佛吉尼亚海滩

As an example, the column ANSWER_TEXT from cf_Answer displays: 佛吉尼亞海灘

但在VBA select语句:

But a select statement in VBA:

sqlstmt = "SELECT ANSWER_TEXT AS ans_text FROM cf_Answer"
Set rst_a = dbs.OpenRecordset(sqlstmt, dbOpenSnapshot)

rst_a![ans_text] 返回 ??????

我知道这已经是与UTF-8编码,但我不能找到一种方式来进行设置。有没有办法将其设置在表中?目前,ANSWER_TEXT是数据类型备忘录的。或者,也许有一种方法来设置VBA来理解这些字?

I know this has something to do with UTF-8 encoding but I cannot find a way to set it. Is there a way to set it in the table? Currently, ANSWER_TEXT is of datatype memo. Or perhaps there is a way to set VBA to understand those characters?

任何人都可以点满我朝着正确的方向?

Can anyone at least point me in the right direction?

推荐答案

该问题可能是由于您在何处显示该UNI code文本。

The issue may be due to where you're displaying that unicode text.

我在我的表粘贴这些相同的字符在文本字段中。检索它们与使用DLookup 在即时窗口,使他们因为眼前的窗口不显示单code,你希望被显示为问号。

I pasted those same characters into a text field in my table. Retrieving them with DLookup in the Immediate window causes them to be displayed as question marks because the Immediate window does not display unicode as you wish.

? DLookup("some_text", "tblFoo", "id = 1")
??????

A MSGBOX 也显示他们为问号。

A MsgBox also displays them as question marks.

MsgBox DLookup("some_text", "tblFoo", "id = 1")

然而,一个格式文本框控件确实有处理单code正确的能力。绑定文本框,其中包含这些字符的领域给了我这个...

However a form text box control does have the capability to handle unicode properly. Binding the text box to the field which contains those characters gives me this ...

一个查询还可以参考UNI code字,而这使用一个在其,其中条款,当查询的数据表视图中打开正确显示它们。

A query can also reference unicode characters, and this uses one in its WHERE clause and displays them all correctly when the query is opened in Datasheet View.

SELECT f.id, f.some_text
FROM tblFoo AS f
WHERE (((f.some_text) Like '佛*'));

我怀疑这一切都归结到你如何试图利用这些单code字符,在那里你显示它们。

I suspect this all comes down to how you're trying to use those unicode characters and where you're displaying them.

在评论,你说写那些单code字符的文本文件将产生唯一的问号。但是,如果你写单code到一个文本文件(如以下步骤),并在编辑器中,它能够处理单code正确,你会看到你在数据表看到相同的字符显示文件视图在那里它们被存储在表中的。该截图显示了写字板打开,这是从下面的code创建的文件。

In a comment, you stated writing those unicode characters to a text file would produce only question marks. However, if you write unicode to a text file (as in the procedure below) and display the file in an editor which is capable of handling unicode correctly, you will see the same characters you see in Datasheet View of the table where they are stored. This screenshot shows Wordpad opened with the file which was created from the code below.

Dim objFso As Scripting.FileSystemObject
Dim objFile As Scripting.TextStream

Set objFso = New Scripting.FileSystemObject
Set objFile = objFso.OpenTextFile(CurrentProject.Path & _
    Chr(92) & "unicode.txt", ForWriting, True, TristateTrue)
objFile.Write DLookup("some_text", "tblFoo", "id = 1")
objFile.Close
Set objFile = Nothing
Set objFso = Nothing

这篇关于外文字符显示为?????在2003年VBA,如何设置UTF-8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆