Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Selection.QueryTable problem

Hi,

I am trying to use the following in an excel (2003) spread sheet:

With Selection.QueryTable
..Connection= "ODBC;DSN=Live;UID=admin;;SERVER=LIVE;DBNAME=DATA; LUID=admin;"
.CommandText = strSelectStatement
.Refresh BackgroundQuery:=False
End With

and I keep getting :

Error Number: 1004
Error Description: Application-defined or object-defined error

I have had a quick look at the help files and online and have tried a number
of alternatives but with no success.

Any help/tips greatly appreciated.

Thanks,
J
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default Selection.QueryTable problem

Selection.QueryTable will give that error.
This is not proper way to refer to a QueryTable.
You can do, for example:

With ActiveSheet.QueryTables(1)
'if 1 is the correct index of the required querytable.
'else replace 1 with the correct index.

Sharad
"JenC" wrote in message
...
Hi,

I am trying to use the following in an excel (2003) spread sheet:

With Selection.QueryTable
.Connection=
"ODBC;DSN=Live;UID=admin;;SERVER=LIVE;DBNAME=DATA; LUID=admin;"
.CommandText = strSelectStatement
.Refresh BackgroundQuery:=False
End With

and I keep getting :

Error Number: 1004
Error Description: Application-defined or object-defined error

I have had a quick look at the help files and online and have tried a
number
of alternatives but with no success.

Any help/tips greatly appreciated.

Thanks,
J



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Selection.QueryTable problem


I've created a Query Editor Add-In for Excel - freely available on my
website.
One of the features is a right-click / Edit.

This is the code I use for returning a QueryTable from a Selection.

Private Function SelectedQueryTable() As QueryTable
Dim qtb As QueryTable, rng As Range, rngResult As Range

If Not ActiveSheet Is Nothing Then
On Error Resume Next
Set rng = Selection.Cells(1)
On Error GoTo 0
If Not rng Is Nothing Then
For Each qtb In ActiveSheet.QueryTables
On Error Resume Next
Set rngResult = qtb.ResultRange
On Error GoTo 0
If Not rngResult Is Nothing Then
If Not Intersect(rng, rngResult) Is Nothing Then
Set SelectedQueryTable = qtb
Exit For
End If
End If
Next
End If
End If
End Function


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"JenC" wrote in message
...
Hi,

I am trying to use the following in an excel (2003) spread sheet:

With Selection.QueryTable
.Connection=
"ODBC;DSN=Live;UID=admin;;SERVER=LIVE;DBNAME=DATA; LUID=admin;"
.CommandText = strSelectStatement
.Refresh BackgroundQuery:=False
End With

and I keep getting :

Error Number: 1004
Error Description: Application-defined or object-defined error

I have had a quick look at the help files and online and have tried a
number
of alternatives but with no success.

Any help/tips greatly appreciated.

Thanks,
J



Reply
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
Selection problem Just wondering Excel Discussion (Misc queries) 2 November 6th 09 01:54 AM
Problem of selection.delete Radhakrishna k.v.n.r[_2_] Excel Worksheet Functions 7 October 27th 07 11:50 AM
Selection problem with recorder brian Excel Discussion (Misc queries) 2 September 19th 06 12:24 AM
Cannot Group that selection Problem PFL Excel Discussion (Misc queries) 5 January 5th 05 02:07 AM
range selection problem derekc[_12_] Excel Programming 2 June 18th 04 04:41 PM


All times are GMT +1. The time now is 12:16 AM.

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

About Us

"It's about Microsoft Excel"