Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA - Create Pass Thru Query without ODBC DSN??

Status
Not open for further replies.

stephenmbell

IS-IT--Management
Jan 7, 2004
109
US
Is it possible to programatically create a pass thru query that connects to SQL server without having a DSN on that machine?

I can't seem to get it to work.

Thanks
sb
 
Google "vba sql server dsn-less connection" you will get back all kinds of sample code
 
Thank you.

I know how to create a connection via ADO.

The end result that I am looking for is to simply open a "table view" result set in access. Basically, click a button, open a query to be displayed to the end user. I don't know how to do this easily with ADO.

Is this possible?

Thanks
sb
 
I typically create and save a generic pass-through query and use a little dao code to set the connection and SQL properties.
Code:
Sub UpdatePTConnection(pstrPTQuery As String, pstrServer As String, pstrDatabase As String, _
        pstrUID As String, pstrPwd As String)
    'ODBC;Driver={SQL Server};Server=XXXXX,3001;Database=xxx;Uid=xxx;Pwd=xxx
    Dim strConnection As String
    Dim db As DAO.Database
    Dim qd As DAO.QueryDef

    strConnection = "ODBC;Driver={SQL Server}" & _
        ";Server=" & pstrServer & _
        ";Database=" & pstrDatabase & _
        ";Uid=" & pstrUID & _
        ";Pwd=" & pstrPwd

    Set db = CurrentDb
    db.QueryDefs.Refresh
    Set qd = db.QueryDefs(pstrPTQuery)
    qd.Connect = strConnection
    db.QueryDefs.Refresh
    Set qd = Nothing
    Set db = Nothing
       
End Sub

Duane
Hook'D on Access
MS Access MVP
 
That looks like it may work. What happens if the database is shared? And furthermore, what happens if it is shared and more than 1 person goes to run this process at once?

Thanks for the response
sb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top