Connecting Tech Pros Worldwide Help | Site Map

dynamically determining queries to tables?

  #1  
Old July 11th, 2007, 04:05 PM
Yin99
Guest
 
Posts: n/a
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, 04:45 PM
Rich P
Guest
 
Posts: n/a

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, 05:05 PM
Allen Browne
Guest
 
Posts: n/a

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, 07:05 PM
Steve
Guest
 
Posts: n/a

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
>

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 14th, 2005 04:15 AM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 11:37 PM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 09:56 PM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 03:15 AM