Access query recordset result output to word shows special characters

时间:2017-07-12 11:44:47

标签: vba ms-access ms-word access-vba ms-access-2010

Problem Description: I am using Microsoft Access Plus 2010, with below code to export the result of query to Word table. However, there are all kinds of special characters exported if the record is over 255 characters.

Below are the query, VBA etc.

Query name: Qa

Query function: select field from Ta

VBA:

Dim qbf As QueryDef
Dim dabase As Database
Set dabase = CurrentDb
Set qdf = dbase.QueryDefs(Qa)
Dim results As Recordset
Dim flds As String
Set results = qdf.OpenRecordset()
While (Not results.EOF)
    doc.addRecord results
    results.MoveNext
Wend
qdf.Close

Public Sub addRecord(pubRecordSet As Recordset)
flds = pubRecordSet.Fields("fieldname")
    mTable.cell(1, 1).range.InsertAfter (flds)
...
End Sub

Where 'mTable' is a Word table object, 'fieldname' is the name of the field to be exported to Word Table. This VBA in general works fine when the length of flds is less than 255, however, it throws a lot of special characters in the Table cell if the length exceeds 255.

Example on special characters exported to Word table cell:

 退D瞻껙皿  Ƭ" "  ᬈ௩Hȷ⫗ 鋨D૝૝ィ௨瞻껥皿௲Ǭ" "Tೕ ŮԱ ࿨ซ鐌D

I checked the limitation of MS Access from link here,请添加一个类。它提到查询的记录集是1GB,我的数据更少(~255个字符)。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

我认为它们被截断或损坏几乎肯定与此处列出的原因之一有关:http://allenbrowne.com/ser-63.html

根据定义,如果长度超过255个字符,它们将被解释为备注或长文本(相同的定义 - 备注是数据类型的旧名称)。