Selection.QueryTable.Refresh

Kathleen_0422

Board Regular
Joined
May 5, 2011
Messages
64
Hello

I am trying to write a Workbook.open event and I need to refresh a query table that taps into a SQL server.

How do I pass the User ID and password?

Thanks in advance for any help.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
I believe you do it within the connection string:

Rich (BB code):
Dim con As connection 
Set con = New connection 
con.ConnectionString = "ODBC;DSN=DB01;UID=LOGIN;PWD=PASSWORD;Database=MyDatabase" 
 
Worksheets("Received").QueryTables.Add(Connection:=con, Destination:=Worksheets("WS").Range("A1"), SQL:=SQL).Refresh 
 
con.close 
set con = nothing
 
Upvote 0
Thanks but......

Do I need to set a reference up? If so which one? I am getting an error when I try to run stating:

User defined type not defined
 
Upvote 0
I'm not sure, can you run the quertytable connection manually with the VB recorder on and see what it says?
 
Upvote 0
Thanks, tried that but the query table is very large and when I record the macro it gets an error with the recorder. Data is returned but the recorder has red lines.

If I try to record a macro to simply refresh credentials do not appear in recorded content.
 
Upvote 0
Thanks, tried that but the query table is very large and when I record the macro it gets an error with the recorder. Data is returned but the recorder has red lines.

If I try to record a macro to simply refresh credentials do not appear in recorded content.

And it doesn't work when you insert the reference in DB01?
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,738
Members
452,940
Latest member
Lawrenceiow

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top