web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

VBA Connection String - Data Source name not found and no default driver specified.

(0) ShareShare
ReportReport
Posted on by

I am calling a function that creates the connection string from another window in the VBA file.  My variables populate fine.  When It comes back to the window and tries to execute oconn.open msconnection, I get an error: [Microsoft][ODBC Driver Manager] Data Source name not found and no default driver specified.  Has anybody seen this?  This should work.  Do i need to register a DLL and then add something as a reference in the VBA file?  Any help would be appreciated.  Thanks!

Private Sub Window_BeforeOpen(OpenVisible As Boolean)
     Dim oconn As New ADODB.Connection
     CheckGroup
     oconn.Open msconnection
End Sub

Function CheckGroup()
Dim ocn As ADODB.Connection
Dim usrObj 'As userinfo ???
Set usrObj = VbaGlobal.UserInfoGet
CheckGroup = True
Set ocn = New ADODB.Connection
mdatasourcename = "DYNAMICS GP 2016"
ocn.Open "dsn=" & mdatasourcename & ";UID=;PWD=;"
mSQLserverName = ocn.Properties.Item("Server Name")
mInterCompanyID = usrObj.IntercompanyID()
'mUser = usrObj.UserName
'mUserID = usrObj.UserID
'mSQLpassword = ""
If Len(mInterCompanyID) > 2 Then
msconnection = "Provider=SQLOLEDB.1;Data Source=" & mSQLserverName _
& ";User ID=;Password=;Initial Catalog=" & mInterCompanyID
Exit Function
End If
CheckGroup = False
End Function

Categories:
I have the same question (0)
  • Verified answer
    David Musgrave MVP GPUG All Star Legend Moderator Profile Picture
    14,095 Most Valuable Professional on at

    Hi

    I am not sure what you are trying to do, but the UserInfoGet object returns the connection. You don’t need to use connection strings at all.

    If you want to share the connection across windows, declare it as public and then you can reference it from the other window.

    https://winthropdc.wordpress.com/2009/01/11/modifier-reading-and-writing-data-with-ado-example/

    https://winthropdc.wordpress.com/2008/10/29/using-ado-with-vba-with-report-writer/

    I would ask…. why use VBA at all. GP Power Tools can replace most VBA customisations with code that is much more stable, reliable, easier to develop and maintain and works on the web client.

    https://winthropdc.wordpress.com/2019/08/12/gppt-replacing-vba-with-gp-power-tools-developer-tools/

    There are plenty of examples on the GP Power Tools Portal – Samples Page: https://winthropdc.wordpress.com/gp-power-tools-portal/gp-power-tools-samples/

    User defined fields:

    https://winthropdc.wordpress.com/2020/01/31/gppt-beginners-guide-to-adding-custom-fields-introduction/

    Cool lookup enhancements:

    https://winthropdc.wordpress.com/2020/08/17/gppt-free-sql-search-across-multiple-fields-lookup-example/

    https://winthropdc.wordpress.com/2020/08/19/gppt-free-automatic-lookup-example/

    Regards

    David

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 544 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans