|
-
Nov 17th, 2011, 08:30 PM
#1
Thread Starter
Hyperactive Member
How to refer to QueryTable by name
I have a question about qy.WorkbookConnection and qy.Name where qy is defined as QueryTable. The qy.WorkbookConnection is 'con2' and the qy.Name is 'Query from MS Access Database_5'.
How can I change the SQL for this specific qy.WorkbookConnection or qy.Name? I can loop through all of the worksheets and all of the querytables searching for the specific connection or name, but I'd like to refer to the WorkbookConnection (or Name) directly by its name. Hope this isn't too confusing.
Thanks
-
Nov 18th, 2011, 10:33 AM
#2
Re: How to refer to QueryTable by name
Is this VB6 or some form of VBA?
-
Nov 24th, 2011, 08:36 PM
#3
Thread Starter
Hyperactive Member
Re: How to refer to QueryTable by name
-
Nov 25th, 2011, 03:38 AM
#4
Re: How to refer to QueryTable by name
Thread moved from the 'VB6' forum to the 'Office Development/VBA' forum (while VBA and VB6 have some similarities, they are not the same thing)
-
Nov 25th, 2011, 04:59 AM
#5
Re: How to refer to QueryTable by name
this should work to set a specific query table, by name, to an object
vb Code:
For Each q In Sheets(1).QueryTables If q.Name = myName Then Exit For Next
if the for each does not find a table by that name then q will be a nothing object on completion, else it will contain the querytable object
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 25th, 2011, 09:04 AM
#6
Thread Starter
Hyperactive Member
Re: How to refer to QueryTable by name
Thanks for reply. But I was asking if there was a way to directly refer to the QueryTable by name rather than looping through all the QueryTable's and checking their names.
-
Nov 25th, 2011, 09:54 PM
#7
Re: How to refer to QueryTable by name
no, index only
you could store the names in a collection
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|