[算表] ADO在CopyFromRecordset時當機
軟體:Excel
版本:2013
各位板上的大大好。
我有一份生產管制表在區網的Server主機上
我新開了一份Excel寫了如下程式,結果在最關鍵的CopyFromRecordset時當機了。
Sheet name = Notice
========這個是寫在新開的Excel上的按鈕=======
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
D = Date
TM = Month(D)
N = 3
DueDate = DateAdd("d", N, D)
WBPath = "\\Server\共用\2019生產管制表.xlsx"
MS = "SELECT * From [" & TM & "月$]" & _
" WHERE 預交日期=" & DueDate
GetData MS, WBPath
End Sub
============以下是寫在Module裡的Sub=======
Sub GetData(MS As String, WBPath As String)
'This sub is used to fetch data from produciton schedule.
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
請問這是哪邊出問題了呢?
煩請高手解惑,感恩。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.33.116.8 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Office/M.1571035842.A.9E8.html
※ 編輯: yimean (114.33.116.8 臺灣), 10/14/2019 14:57:06
→
10/14 15:27,
6年前
, 1F
10/14 15:27, 1F
→
10/14 15:27,
6年前
, 2F
10/14 15:27, 2F

→
10/14 15:28,
6年前
, 3F
10/14 15:28, 3F
→
10/14 15:29,
6年前
, 4F
10/14 15:29, 4F
→
10/14 15:29,
6年前
, 5F
10/14 15:29, 5F
→
10/14 15:32,
6年前
, 6F
10/14 15:32, 6F
→
10/14 15:32,
6年前
, 7F
10/14 15:32, 7F
→
10/14 16:12,
6年前
, 8F
10/14 16:12, 8F
→
10/14 16:13,
6年前
, 9F
10/14 16:13, 9F
→
10/14 16:15,
6年前
, 10F
10/14 16:15, 10F
→
10/14 16:19,
6年前
, 11F
10/14 16:19, 11F
→
10/14 16:20,
6年前
, 12F
10/14 16:20, 12F
→
10/14 16:27,
6年前
, 13F
10/14 16:27, 13F
→
10/14 16:28,
6年前
, 14F
10/14 16:28, 14F
→
10/14 16:39,
6年前
, 15F
10/14 16:39, 15F
→
10/14 16:40,
6年前
, 16F
10/14 16:40, 16F
→
10/14 16:43,
6年前
, 17F
10/14 16:43, 17F
→
10/14 16:45,
6年前
, 18F
10/14 16:45, 18F
→
10/14 16:46,
6年前
, 19F
10/14 16:46, 19F
→
10/14 16:47,
6年前
, 20F
10/14 16:47, 20F
→
10/14 16:48,
6年前
, 21F
10/14 16:48, 21F
→
10/14 16:56,
6年前
, 22F
10/14 16:56, 22F
→
10/14 20:47,
6年前
, 23F
10/14 20:47, 23F
Office 近期熱門文章
PTT數位生活區 即時熱門文章