0

動的selectステートメントを作成するために、現在、クエリを保持するための一時ファイルを作成しています(使用されている結合とデコードの数により、30k以上の文字)。データをExcelに返すために、完全なselectステートメントを含むこの一時ファイルを使用したいと思います。

現在のコードを使用すると、短いselectステートメントしか実行できません。私が作成した文字列は、何らかの理由で切り捨てられているようです。

これが私が使用しているコードのスニペットで、ファイルを作成し、現在同じ文字列を実行しようとしています。

' Set file details
fileDir = "C:\temp\"
filePath = "C:\temp\" & node & "_SRO_TCs.sql"

'check if directory exists, if not create it
If Dir(fileDir, cbDirectory) = "" Then
MkDir fileDir
End If

' open the file
Open filePath For Output As #1

'Write to file
outputText = sqlQuery3
Print #1, outputText

'open connection
sqlCon.ConnectionString = Conn
  'Cn.CursorLocation = adUseClient
sqlCon.Open

'set and execute sql command
Set sqlCommand.ActiveConnection = sqlCon
sqlCommand.CommandText = sqlQuery3
sqlCommand.CommandType = adCmdText
sqlCommand.Execute

'open recordset
Set sqlRecordSet.ActiveConnection = sqlCon
sqlRecordSet.Open sqlCommand


'copy data to excel
ActiveSheet.Range("A1").CopyFromRecordset (sqlRecordSet)  <<<< This is where i get an error returned when stepping through the code - "Run-time error '91': Object variable or With block variable not set"

'close connections
sqlRecordSet.Close
sqlCon.Close

'Close file
Close #1

作成されたファイルを確認すると、SQLselectステートメントが機能しています。このファイルまたは文字列を実行できるようにしたいと思います。助けてください!

4

1 に答える 1

0

Command Execute メソッドは次のようになります。

Set recordset = command.Execute( RecordsAffected, Parameters, Options )

あなたのコードはかなり異なります。より短い SQL ステートメントで動作すると言ったので、以前はコードをあまり詳しく調べていませんでした。

于 2012-05-12T16:42:13.487 に答える