jjobrien03
New Member
- Joined
- Sep 2, 2014
- Messages
- 41
I am having trouble using named ranges to define my connection variables. The code works when I just type in the server/database names but I cannot get them to reference properly when using excel named ranges.
Database = positions
Server = MyDatabase/SQLEXPRESS
Appreciate any help - thanks.
Database = positions
Server = MyDatabase/SQLEXPRESS
VBA Code:
Sub SendPositionstoSQL()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sConnString As String
Dim Server As String
Server = Range("SQLServer").Value
Dim Dbase as String
Dbase = Range("Dbase").Value
sConnString = "Provider=SQLOLEDB;Data Source=Server;" & _
"Initial Catalog=Dbase;" & _
"Integrated Security=SSPI;"
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.Open sConnString
Appreciate any help - thanks.