Wrong path

Kurt

Well-known Member
Joined
Jul 23, 2002
Messages
1,664
Hello Everyone,

I have the following code:

Code:
Sub get_applications()
    Dim conn As New Connection
    Dim rec As New Recordset
    Dim comm As New Command
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Worksheets("command")
    'Set ws = Worksheets("command")
    conn.Open "Provider=microsoft.jet.oledb.4.0;" + _
        "Data Source=CHECSQLDEV1\NEO"
        '"Data Source=C:\FromDyer.mdb;"
    Set comm.ActiveConnection = conn
    strSQL = "USE CHEC SELECT * FROM dbo.SMT_Branches"
     comm.CommandText = strSQL
    rec.Open comm
    ws.[a1].CopyFromRecordset rec
    rec.Close: conn.Close
End Sub

However the information I am trying to access is on a sql serve but the workbook is on my local drive. What is the correct syntax to make the code see the sql server and the workbook that resides on my local disk drive.

TIA

Have a great day everyone!

Kurt
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Connection strings

Hello Andrew,

Thanks I have bookmarked your reference. Yes it will help for the future.

I know the problem in the code is here:

Code:
    'conn.Open "OLEDB;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Data Source=checsqldev1\neo3;"
    conn.Open "Provider=microsoft.jet.oledb.4.0;" + _
        "Data Source=checsqldev1\neo3"

Any other suggestions for me.

Thanks for looking at this and have a great day!

Kurt
 
Upvote 0
Almost there

Hello Andrew,

Thanks I think it will work except for one thing.

I have the OLE Autmoation referenced check in the Tools References in the VBA editor.

The error message I get now is:

"Provier cannot be found, it may not be properly installed."

Which references should I be using?

Thanks,

Kurt
 
Upvote 0
sqloledb.dll

Hello Andrew,

Yes it is there.

What should I check for next?

Thanks,

Kurt
 
Upvote 0
thanks I registered the dll ok but still errors

Hello Andrew,

Thanks I was able to register the dll.

Code:
Sub get_applications()
    Dim conn As New Connection
    Dim rec As New Recordset
    Dim comm As New Command
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Worksheets("command")
    conn.Open "Provider=microsoft.jet.oledb.4.0;Data Source=checsqldev1\neo3;Initial Catalog = dbo.SMT_Branches"
     Set comm.ActiveConnection = conn
    strSQL = "USE CHEC SELECT * FROM dbo.SMT_Branches"
    comm.CommandText = strSQL
    rec.Open comm
    ws.[a1].CopyFromRecordset rec
    rec.Close: conn.Close
End Sub

This should work what am I doing wrong or what do I need to check next?

Thanks for all of your effort.

Kurt
 
Upvote 0
Query will work

Hello Andrew,

Here is a stump the commissioner. I was able to create a query and it does work!

Code:
Sub getdata_test()
'
' getdata_test Macro
' Macro recorded 10/2/2006 by Kurt
'

'
    With ActiveSheet.QueryTables.Add(Connection:=Array( _
        "OLEDB;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Data Source=checsqldev1\neo3;Use Procedure for Prepare=1" _
        , _
        ";Auto Translate=True;Packet Size=4096;Workstation ID=KNICHOLS;Use Encryption for Data=False;Tag with column collation when possi" _
        , "ble=False;Initial Catalog=chec"), Destination:=Range("A1"))
        .CommandType = xlCmdTable
        .CommandText = Array("""chec"".""dbo"".""SMT_Branches""")
        .Name = "+New SQL Server Connection_2"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .SourceConnectionFile = _
        "C:\Documents and Settings\knichols\My Documents\My Data Sources\checsqldev1_neo3 chec SMT_Branches.odc"
        .Refresh BackgroundQuery:=False
    End With
End Sub

What's up with that? And I was able to do this before without registering the dll.

thanks,

Kurt
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,412
Members
448,960
Latest member
AKSMITH

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