Hello All,
I have a workbook with several spreadsheets that have reports on them. Im attempting to iterate through each worksheet, each querytable on the worksheet, and replace the database connection info with the info that i get from the user by prompting the user for the information on startup. I havent written vb in forever, so i apoligize in advance. Heres my basic code:
oConnection.ConnectionString = "Provider=sqloledb;" & _
"Data Source=" & txtServer.Value & ";" & _
"Initial Catalog=" & txtDataBase.Value & ";" & _
"User Id=" & txtUserName.Value & ";" & _
"Password=" & txtPassword.Value
Do While x < ThisWorkbook.Worksheets.Count
Set oWorkSheet = ThisWorkbook.Worksheets(x)
Do While y < oWorkSheet.QueryTables.Count
Set oQueryTable = oWorkSheet.QueryTables
oQueryTable.Connection = oConnection
y = y + 1
Loop
x = x + 1
Loop
It consistently bombs out on this line:
oQueryTable.Connection = oConnection
I did try using the set keyword. Any help would be greatly appreciated.
Thanks,
Ryan
I have a workbook with several spreadsheets that have reports on them. Im attempting to iterate through each worksheet, each querytable on the worksheet, and replace the database connection info with the info that i get from the user by prompting the user for the information on startup. I havent written vb in forever, so i apoligize in advance. Heres my basic code:
oConnection.ConnectionString = "Provider=sqloledb;" & _
"Data Source=" & txtServer.Value & ";" & _
"Initial Catalog=" & txtDataBase.Value & ";" & _
"User Id=" & txtUserName.Value & ";" & _
"Password=" & txtPassword.Value
Do While x < ThisWorkbook.Worksheets.Count
Set oWorkSheet = ThisWorkbook.Worksheets(x)
Do While y < oWorkSheet.QueryTables.Count
Set oQueryTable = oWorkSheet.QueryTables
oQueryTable.Connection = oConnection
y = y + 1
Loop
x = x + 1
Loop
It consistently bombs out on this line:
oQueryTable.Connection = oConnection
I did try using the set keyword. Any help would be greatly appreciated.
Thanks,
Ryan