The_Kurgan
Active Member
- Joined
- Jan 10, 2006
- Messages
- 270
I realize this is probably a long shot, but would anyone have sample VBA SQL code where you're joining tables from different servers? I've done a lot with pulling data from tables on one server, but not more.
TIA
For some frame of reference only, this is some sample code where I'm adding column names from a chosen table into a listbox (no joining... just a straight query).
TIA
For some frame of reference only, this is some sample code where I'm adding column names from a chosen table into a listbox (no joining... just a straight query).
Code:
Set objMyConn = New ADODB.Connection
Set objMyRecordset = New ADODB.Recordset
Dim strSQL As String
'Open Connection'
objMyConn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Data Source=" & MyServer & ";Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=SECONDARYTS;Use Encryption for Data=False;Tag with column collation when possible=False;Initial Catalog=" & MyDB
objMyConn.Open
'Set and Excecute SQL Command'
strSQL = "SELECT column_name FROM information_schema.columns WHERE table_name = '" & DB_Data.ListBox1.Text & " ';"
'Open Recordset'
Set objMyRecordset.ActiveConnection = objMyConn
objMyRecordset.Open strSQL
'Copy Data to Excel'
objMyRecordset.MoveFirst
iter = 0
Do Until objMyRecordset.EOF = True
DB_Data.ListBox2.AddItem objMyRecordset(0)
objMyRecordset.MoveNext
iter = iter + 1
Loop
objMyConn.Close
Set objMyRecordset = Nothing
Set objMyConn = Nothing