且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

外文字符显示为?????在2003年VBA,如何设置UTF-8?

更新时间:2023-11-27 13:33:46

该问题可能是由于您在何处显示该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 ...

外文字符显示为?????在2003年VBA,如何设置UTF-8?

一个查询还可以参考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.

外文字符显示为?????在2003年VBA,如何设置UTF-8?

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