Connecting Tech Pros Worldwide Help | Site Map

dynamically determining queries to tables?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 11th, 2007, 03:05 PM
Yin99
Guest
 
Posts: n/a
Default dynamically determining queries to tables?

I have a recordset that is created via:
Dim rs As Recordset
Set rs = Me.RecordsetClone

which if I understand correctly fills the recordset with the form's
recordsource. Now if I run the vb code:
MsgBox rs.Name

it shows me what query that generated the recordset (e.g.
"queryCustomers")

Now if I look at that query in Access, I see what tables it uses.

Here's my question- Since I know rs.Name tells me what query the
recordset got
it's data from, is there a way in the VB code to now access that
corresponding
query and thus access the originating tables?

-Yin


  #2  
Old July 11th, 2007, 03:45 PM
Rich P
Guest
 
Posts: n/a
Default Re: dynamically determining queries to tables?


Private Sub Command6_Click()
Dim DB As DAO.Database, QD As DAO.QueryDef
Set DB = CurrentDb
Set QD = DB.QueryDefs(Me.RecordSource)
Debug.Print QD.SQL
End Sub



Rich

*** Sent via Developersdex http://www.developersdex.com ***
  #3  
Old July 11th, 2007, 04:05 PM
Allen Browne
Guest
 
Posts: n/a
Default Re: dynamically determining queries to tables?

This example shows you how to loop through the fields of your recordset,
identifying the SourceTable for each one:
http://allenbrowne.com/func-DAO.html#ShowFieldsRS

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Yin99" <ws@ziowave.comwrote in message
news:1184165912.102282.79700@n2g2000hse.googlegrou ps.com...
Quote:
>I have a recordset that is created via:
Dim rs As Recordset
Set rs = Me.RecordsetClone
>
which if I understand correctly fills the recordset with the form's
recordsource. Now if I run the vb code:
MsgBox rs.Name
>
it shows me what query that generated the recordset (e.g.
"queryCustomers")
>
Now if I look at that query in Access, I see what tables it uses.
>
Here's my question- Since I know rs.Name tells me what query the
recordset got
it's data from, is there a way in the VB code to now access that
corresponding
query and thus access the originating tables?
>
-Yin
>
  #4  
Old July 11th, 2007, 06:05 PM
Steve
Guest
 
Posts: n/a
Default Re: dynamically determining queries to tables?

You can get the SQL of the query and parse out the tables from the From
clause.

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
resource@pcdatasheet.com



"Yin99" <ws@ziowave.comwrote in message
news:1184165912.102282.79700@n2g2000hse.googlegrou ps.com...
Quote:
>I have a recordset that is created via:
Dim rs As Recordset
Set rs = Me.RecordsetClone
>
which if I understand correctly fills the recordset with the form's
recordsource. Now if I run the vb code:
MsgBox rs.Name
>
it shows me what query that generated the recordset (e.g.
"queryCustomers")
>
Now if I look at that query in Access, I see what tables it uses.
>
Here's my question- Since I know rs.Name tells me what query the
recordset got
it's data from, is there a way in the VB code to now access that
corresponding
query and thus access the originating tables?
>
-Yin
>

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.