Hi, I have code that will query an external data source using my username and password in VBA (username and password are supplied through a userform. This way, I will not see the Excel dialog box pop up for my username and password. This code works just fine (User, Password, and SQL are variables...self explanatory what each is):
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"ODBC;DSN=DP1H; UID=" & User & ";PWD=" & Password & ";MODE=SHARE;DBALIAS=DP1H;ASYNCENABLE=0;", _
Destination:=Range("$A$2")).QueryTable
.CommandText = SQL
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
Now, where I'm running into trouble is when I want to return results in a pivot table rather than rows on a sheet. For the next piece of code to work, I have a pivot table already created on sheet3 that was originally setup to query an external source (editing a normal pivot table not setup with the external source doesn't work). I edit the connection and commandtext, but as soon as I run the commandtext line, Excel's username/password dialog box will pop up, but I have already provide that information in the connection. Can anyone help me be able to suppress the Excel dialog box and use the username and password that I supplied???
ActiveWorkbook.Worksheets(Sheet3.Name).PivotTables("PivotTable3").PivotCache.Connection = "ODBC;DSN=DP1H; UID=" & User & ";PWD=" & Password & ";MODE=SHARE;DBALIAS=DP1H;TABLETYPE='TABLE';GRANTORLIST="";PATCH1=1;ASYNCENABLE=0;"
ActiveWorkbook.Worksheets(Sheet3.Name).PivotTables("PivotTable3").PivotCache.CommandText = SQL
Bookmarks