Execute Sql Query In Java Code
Active5 years ago
VBA offers the following methods for executing Action queries in code: RunSQL Executes a SQL statement, not a saved query. Shows messages that require user interaction. OpenQuery Runs a saved query, not a SQL statement. Shows messages that require user interaction. Execute Executes either a SQL statement or a saved query. Does not show messages that require user interaction. Use the VBA DAO Database Execute command, rather than DoCmd.RunSQL and DoCmd.OpenQuery, to run action queries without warning messages and avoid changing the Access SetWarnings status. Background Action queries in Microsoft Access are queries that add, modify, or delete records from tables using INSERT, UPDATE, and DELETE commands (or create a.
Very new to any form of code. Attempting to run a script in VBA that will pull data from an access database using SQL and put it into an excel spreadsheet. Code is similar to below. Runs clean but I don't know how to use the data it is pulling. Thanks in advance.
Toad62
Toad62Toad62
1 Answer
You need to fill your recordset object (That's the rs variable you declared). I have changed the code below to do just that. You can then copy the results from the recordset directly into a range with
RANGE.copyfromrecordset <yourrecordset>
below I have added that as well where I dump the results into SHeet1.Range('A1'). You'll probably want to change that. EDITED TO ADD: Just realized you are using late binding for ADODB. I have adjusted the code so it will actually work.You can think of the RecordSet (rs in this case) as a virtual table that holds the results of the SQL. You can interact with the RecordSet on a record by record (with rs.MoveFirst, MoveNext, MoveLast ) and field by field basis (by iterating through the rs.fields collection), or you can just dump the results in a range.
JNevillJNevill