软件: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
恳请高手指导,感谢。