
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
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:
Cool lookup enhancements:
https://winthropdc.wordpress.com/2020/08/19/gppt-free-automatic-lookup-example/
Regards
David