Connection to System ODBC

C

Candyman

I am new at this and am trying to pull a sql statement , run a query, and
spit out results to table, report, or Excel. I can run the SQL in Excel or
another SQL tool, but I want to track all my SQL in one Db. I just am not
familiar with Access objects. Here is striped out 'meat' of code with a
couple of comments. Can you point me in the right direction? Some stuff I
pulled from help files.

Sub btnRunSQL_Click()
Dim wrkMain As Workspace 'Don't know what this is
Dim conExternal As Connection
Dim DbExternal As Database
Dim rsDB As Recordset
Dim qd As DAO.QueryDef
Dim mySQL As String

' Create ODBCDirect Workspace object instead of Microsoft
' Jet Workspace object.
Set wrkMain = CreateWorkspace("NewODBCWorkspace", "admin", "", dbUseODBC)


' Open Connection object based on information in the connect string.

Set conExternal = wrkMain.OpenConnection("Connection1", , ,
"ODBC;DSN=TheDatabase;UID=TheUserID
;PWD=Thepassword;DBALIAS=TheDatabase;TXNISOLATION=1")

mySQL = Me.SQLStatement


***Not sure what line to use...
Set qd.sql = mySQL
' Set DbExternal = conExternal.Database
Set rsDB = qd.OpenRecordset()


With DbExternal
How do I put this the results in a temp table, report or xls?
End With

DbExternal.Close
wrkMain.Close
End Sub

I'm stumped. Please help
Candyman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top