PDA

View Full Version : VBA - Connecting to Database using System DSN



ysvsr1
03-16-2016, 08:25 PM
My goal is to connect to teradata database using VBA and LDAP and execute a few queries.

I have been trying to connect to teradata using various snippets available and could not make it to work, may be because it is ldap and cant get it work.

I found a workaround, there is a vba code some one has written which uses :

With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DSN=" & DNSname & ";;;; ", Destination:=Range("B30"))
.CommandText = Array(RunMacro)
.Name = ReportName
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With

When it executes, it brings up a dialog box and i get to use the ODBC connections already defined, but unfortunately it only shows up Machine data source and File data source connections, is there any thing we can do to show System Data Sources as well? As most of our odbc connections are already defined as System data sources, i can just use that to connect to teradata instead of wasting my time to get it to work in with the vba code.

Gurus Help !