[算表] ADO在某些字段的中文字无法取回

楼主: yimean (温柔杀手)   2019-10-16 14:10:38
软件:Excel
版本:2013
各位板上的大大下午好。承上篇 CopyFrom...当机的问题。
首先感谢Soyoso大大的指导几本上ADO Open当机的问题已经解决了。
但是我把当资料取回来之后发现品名这个字段只要有中文字就会变成空白
其他的字段纵使有中文字也不会有问题。
下方是我的程式码。
ADO在透过网芳取得资料这一块好像有问题。本机都可以运作的很好。
============Notice页面======
Private Sub DueDateCrossing_Click()
Dim MS As String 'SQL command
Dim WBPath As String ' Workbook Path
Dim N As Integer 'To fetch data of N days later, N must smaller than 31
Dim D As Date ' D is refered to Date
Dim TM As Integer ' TM is refered to this month
Dim DueDate As Date 'DueDate is refered to DueDate
Dim DueDateS As String
D = Date
TM = Month(D)
N = 7
DueDate = DateAdd("d", N, D)
DueDateS = "#" & DueDate & "#" 'The symbol "#" is required by date
formate.
WBPath = "D:\desktop\2019生产管制表.xlsx"
MS = "SELECT * From [" & TM & "月$a:q]" & _
" WHERE 预交日期=" & DueDateS
GetData MS, WBPath
End Sub
==================Sub Module=========
Sub GetData(MS As String, WBPath As String)
'This sub is used to fetch data from produciton schedule.
On Error Resume Next
Dim MC As String 'MC is refered to My Connection
Dim MR As ADODB.Recordset 'MR is refered to My Recordset
MC = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & WBPath & ";" & _
"Extended Properties=Excel 12.0;"
Set MR = New ADODB.Recordset
MR.Open MS, MC, adOpenStatic, adLockReadOnly
Worksheets("Notice").Range("A2").CopyFromRecordset MR
End Sub
==========================================
原始资料
https://imgur.com/zVUKxAU
ADO取得的资料
https://imgur.com/NuLslBV
恳请高手指导,感谢。
作者: soyoso (我是耀宗)   2019-10-16 14:42:00
模拟抓取存放该档案的主机,回传资料的b栏也可以正常回传中文,如 https://i.imgur.com/9nEhKra.jpg模拟上我是以模拟器开个winxp,接着共同个子目录,再来抓的所以如果在没有合适解决方式的话,看是否以内文所写的本机可正常运作来看,就复制到本机暂存,读取,删档之类的
楼主: yimean (温柔杀手)   2019-10-16 14:49:00
我这个是本机抓档的结果,网芳的话是会整个Hang住。太神奇
作者: soyoso (我是耀宗)   2019-10-16 14:49:00
当然这也是因为模拟不出内文情况下,所提供的方式,如有其
楼主: yimean (温柔杀手)   2019-10-16 14:57:00
了解,感谢您。
作者: soyoso (我是耀宗)   2019-10-16 15:10:00
14:46方面复制filecopy,删档kill,删档方面要先将变量MRnothing后再删除
楼主: yimean (温柔杀手)   2019-10-16 15:37:00
收到,感谢。

Links booklink

Contact Us: admin [ a t ] ucptt.com