querydef: how to reference external odbc tables

M

mikeg

I can't seem to figure out how to write a query in ms-access(2007) that
points to data in an external odbc...i can do it on the fly in vba code, but
when i save it as a querydef i dont know how to pass along the
connectionstring with the rest of the SQL.
thanks!
Mike G
 
D

Douglas J. Steele

Dim qdfCurr As DAO.QueryDef
Dim strConnection As String
Dim strSQL As String

strSQL = "...."
strConnection = "ODBC;DRIVER={sql server};DATABASE=" & _
DatabaseName & ";SERVER=" & ServerName & _
";Trusted_Connection=Yes;"

Set qdfCurr = CurrentDb.CreateQuerydef("MyQuery", strSQL)
qdfCurr.Connect = strConnection
 

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