Syntax
SQLRetrieveToDocument(ConnectNum)
Remarks
Retrieves the results of a query and places the entire contents into a table in the active document. To use SQLRetrieveToDocument, a macro must have already established a connection using SQLOpen. Also, a query must already have been executed using SQLExecQuery, and results must be pending.
You cannot use SQLRetrieveToDocument to return data from a SQLQueryExec instruction.
Argument | Explanation |
ConnectNum | The unique connection ID of the data source you want to query returned by a previously executed SQLOpen function. If ConnectNum is not valid, SQLRetrieveToDocument returns 0 (zero). |
If the pending query result cannot be returned successfully, SQLRetrieveToDocument returns a negative error value.
Example
The following example establishes a connection to a data source, queries the data source to select every record, and then uses SQLRetrieveToDocument to insert the entire data source in a table in a new Word document.
connect_num = SQLOpen("DSN=test.mdb", output_ref$, 0) ret = SQLExecQuery(connect_num, "Select * from table4 " + \ Quote2$("name")) FileNew ret = SQLRetrieveToDocument(connect_num) ret = SQLClose(connect_num)