SQL connection editing by VBA

Toomicek

New Member
Joined
Oct 8, 2014
Messages
28
Hi there,

I am using SQL query to get data from our database to excel with something like this:

Code:
select distinct kniha.ucet, ks, right(obd_rr,2) + obd_mm as 'období', NAZEV
from kniha 
inner join rozvrh on rozvrh.ucet = kniha.ucet


where obd_mh = '99' and rozvrh.obd_rh = '2017H'

It is pretty simple query and I want to use it from multiple sources (Companies)

Here is connection string:

Code:
Provider=SQLOLEDB.1;
Password=****;
Persist Security Info=True;
User ID=******;
[COLOR=#ff0000]Initial Catalog=COMPANY1;[/COLOR]
Data Source=192.168.******;
Use Procedure for Prepare=1;
Auto Translate=True;
Packet Size=4096;
Workstation ID=*******;
Use Encryption for Data=False;
Tag with column collation when possible=False

I want to change red value in excel so i do not need to manualy enter value every time I want to change source. Is it possible?

Thank you

Tomas
CZECH REPUBLIC
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Re: SQL connection editting by VBA

I have a CONFIG sheet.
i put values in cells.

initial Catalog=sheets("config").range("a3").value
 
Upvote 0
Re: SQL connection editting by VBA

I did. See above.

I ma little bit confused. I am asking if it is possible to put it in whole VBA code like:

Sub myconnection()

CODE

end sub

I am not capable to write everything by myself. I know i should be, but its learning by steps and I am not that far right now.

Thank you
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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