Connecting Tech Pros Worldwide Help | Site Map

dynamically determining queries to tables?

Yin99
Guest
 
Posts: n/a
#1: Jul 11 '07
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

Rich P
Guest
 
Posts: n/a
#2: Jul 11 '07

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 ***
Allen Browne
Guest
 
Posts: n/a
#3: Jul 11 '07

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
>
Steve
Guest
 
Posts: n/a
#4: Jul 11 '07

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