LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Runtime error 1004 - how to solve

I have a very basic excel macro:

Sub CreateQT()

On Error GoTo ErrorHandling

Dim sConn As String
Dim sSql As String
Dim oQt As QueryTable

sConn = "{SQL Native Client};"
sConn = sConn & "Server=.SERVER\SQLExpress;"
sConn = sConn & "AttachDbFilename=testExcel.mdf;"
sConn = sConn & "Database=dbname;Trusted_Connection=Yes;"


sSql = "SELECT dataField "
sSql = sSql & "FROM testTable"

Set oQt = ActiveSheet.QueryTables.Add(Connection:=sConn,
Destination:=Range("a1"), Sql:=sSql)

oQt.Refresh
GoTo No_Error
'End Sub

ErrorHandling:
MsgBox Err.Number & " " & Err.Description

No_Error:
End Sub


but this fails:
Set oQt = ActiveSheet.QueryTables.Add(Connection:=sConn,
Destination:=Range("a1"), Sql:=sSql)

with a 1004 Application-define or object-defined error...

How do I find/debug the couse and get the query to run? (sorry newbie
in this stuff - maybe very basic question)

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Uh oh...Runtime error 1004!!!! zenahs[_7_] Excel Programming 0 March 20th 06 05:16 PM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
Runtime error 1004 Jeannette[_2_] Excel Programming 0 May 13th 04 06:31 AM
Runtime Error 1004 Don[_7_] Excel Programming 2 September 16th 03 08:32 AM
Runtime error '1004': Capinvest Excel Programming 2 August 4th 03 07:16 PM


All times are GMT +1. The time now is 10:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"