VBA ODBC Connection not connecting

Hi Experts (Using Access 2003)

I am using the following code and viewing the results in the intermediate window to see if an connection has been estbalished.....

it work then it doesn;t work.....is the vba correct?

Option Compare Database

Public Function GetQueryLinks()
On Error GoTo Err_GetQueryLinks

    Dim dbs         As DAO.Database
    Dim qdf         As DAO.QueryDef
    Dim wConnect    As String
    
       Set dbs = CurrentDb
        wConnect = "ODBC;Driver=SQL Server;UID=MyUID;PWD=MyPass;Server=SQLLQW4FF43567.global.hire.com,14444;Database=Apples_Oranges;"
        
        For Each qdf In dbs.QueryDefs
            If qdf.Type = dbQSQLPassThrough Then
                qdf.Connect = wConnect
              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

route217JuniorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
Yes, it is correct. Even that much that I use similar code only without the error handling.

Of course, connection errors may cause an error, but I assume your connection string is confirmed.

/gustav
0
route217JuniorAuthor Commented:
hi gustav

in relation to you're question ....no I do not get the connection string as being confirmed. ..

any possible step I could take. ..
0
Gustav BrockCIOCommented:
Then you will have to sort it out. The syntax is correct but only you know server name, port address, etc.

One of mine looks like this:

"ODBC;Description=ABC;DRIVER=SQL Server;SERVER=someserver,11403;Trusted_Connection=Yes;APP=Microsoft® Windows® Operating System;DATABASE=test"

It was partly generated by the ODBC wizard, thus the APP part.

/gustav
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
route217JuniorAuthor Commented:
GUstav - thanks you sir works 100%

this is an extermely good point - for any questions around this subject:

One of mine looks like this:

"ODBC;Description=ABC;DRIVER=SQL Server;SERVER=someserver,11403;Trusted_Connection=Yes;APP=Microsoft® Windows® Operating System;DATABASE=test"
0
Gustav BrockCIOCommented:
You are welcome!

/gustav
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.