Link to home
Start Free TrialLog in
Avatar of route217
route217Flag for United Kingdom of Great Britain and Northern Ireland

asked on

querydef function not working???

Hi Experts (access 2003)
Shot in the dark....

I have the following function to set my SQL connection strings to the following the code incomplete or do i need to tell it (vba code0 that it's a new connection....totally confused...

If i am talking rubbish please step in.....and correct me...

I am trying to connect to SQL and keep on getting a ODBC connection failure error msg...

whats could be wrong....

Public Function GetQueryLinks()
On Error GoTo Err_GetQueryLinks

    Dim qdf As DAO.QueryDef
    Dim StrConn As String
    StrConn = "ODBC;Driver=SQL Server;UID=MyUID;PWD=MyPass;;Port=43533;Database= Apples_Ornages;"
     For Each qdf In CurrentDb.QueryDefs
        If qdf.Connect <> "" Then

            qdf.Connect = StrConn
            Debug.Print qdf.Connect

        End If

    Set qdf = Nothing
    Exit Function

    MsgBox Err.Number & " (" & Err.Description & ") in procedure GetQueryLinks of Module basTableLinks"
    Resume Exit_GetQueryLinks

End Function

Open in new window

Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of route217



sould I add ur vbq to a new sub
No, it was just for inspiration.


is a made u0 name of the database
still getting odb cconnection failed error message
thanks fot it working
Then check the existing connect string of an attached table or one of the queries and adjust your new connection as needed.