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 instant...is 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;Server=SEEEPB4SBT45646.global.Hire.com;Port=43533;Database= Apples_Ornages;"
         
     For Each qdf In CurrentDb.QueryDefs
        If qdf.Connect <> "" Then

            qdf.Connect = StrConn
            Debug.Print qdf.Connect

        End If

        Next
            
Exit_GetQueryLinks:
    Set qdf = Nothing
    Exit Function

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

End Function

Open in new window

Microsoft Access

Avatar of undefined
Last Comment
Gustav Brock

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Gustav Brock

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
route217

gustav

sould I add ur vbq to a new sub
Gustav Brock

No, it was just for inspiration.

/gustav
ASKER
route217

apples_oranges

is a made u0 name of the database
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER
route217

still getting odb cconnection failed error message
ASKER
route217

thanks fot it working
Gustav Brock

Then check the existing connect string of an attached table or one of the queries and adjust your new connection as needed.

/gustav
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.