たくさんのグーグルの後、私はデータベースに接続し、既存の一時テーブルを削除してから新しいものを作成することを望んでいた次のマクロに行き着きました(それを入力して結果を表示します)。
Dim adoCn As ADODB.Connection
Dim adoRs As ADODB.Recordset
Dim adoCm As ADODB.Command
Dim strSQL As String
Set adoCn = New ADODB.Connection
With adoCn
.ConnectionString = "Provider=SQLOLEDB;" & _
"Initial_Catalog=XXX;" & _
"Integrated Security=SSPI;" & _
"Persist Security Info=True;" & _
"Data Source=XXX;" & _
"Extended Properties='IMEX=1'"
.CursorLocation = adUseServer
.Open
End With
Set adoCm = New ADODB.Command
With adoCm
Set .ActiveConnection = adoCn
.CommandType = adCmdText
.CommandText = "IF OBJECT_ID('tempdb..#AgedProducts') IS NOT NULL DROP TABLE #AgedProducts"
.Execute
.CommandText = "CREATE TABLE #AgedProducts " & _
"(Source_Order_Number VARCHAR(255)) " & _
"INSERT INTO #AgedProducts VALUES ('AB-123-456') " & _
"SELECT * FROM #AgedProducts (NOLOCK) "
.Execute
End With
Set adoRs = New ADODB.Recordset
With adoRs
Set .ActiveConnection = adoCn
.LockType = adLockBatchOptimistic
.CursorLocation = adUseServer
.CursorType = adOpenForwardOnly
.Open "SET NOCOUNT ON"
End With
adoRs.Open adoCm
MsgBox "Recordset returned...", vbOKOnly
While Not adoRs.EOF
Debug.Print adoRs.Fields(0).Value
adoRs.MoveNext
Wend
adoCn.Close
Set adoCn = Nothing
Set adoRs = Nothing
クエリを実行すると、次のエラーメッセージが表示されます。
Run-time error '-2147217887 (80040e21)':
The requested properties cannot be supported
このNOCOUNT
行はhttp://support.microsoft.com/kb/235340からのものです(上記のコードの多くがそうであるように)。IMEX=1
注文番号には複数のタイプがある可能性があることを考慮して追加しましたが、そこで問題が発生しているとは思えません。
どんな助けでも大歓迎です!