473,405 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Find TableName of related table

Dear All,

Is ( how) it possible to find the tablename of the table that is related to
a field.

Field CLIENT_TITLE_ID is related to table TITLE

Thanks,

Filip
Nov 13 '05 #1
4 1932
Filips Benoit wrote:
Dear All,

Is ( how) it possible to find the tablename of the table that is related to
a field.

Field CLIENT_TITLE_ID is related to table TITLE


Do you mean in a query? See the DAO reference, Field object, properties.

--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea
Nov 13 '05 #2
This function lists the indexes of a table, and the fields involed in the
index.

If it is a Foreign index, you can use the properties to determine the
foreign table and field.

Function ShowIndexes(strTable As String)
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim ind As DAO.Index
Dim fld As DAO.Field

Set db = DBEngine(0)(0)
Set tdf = db.TableDefs(strTable)
For Each ind In tdf.Indexes
Debug.Print ind.Name, IIf(ind.Primary, "Primary", ""), _
IIf(ind.Foreign, "Foreign", ""), ind.Fields.Count
Debug.Print " Field(s): ";
For Each fld In ind.Fields
Debug.Print fld.Name;
Next
Debug.Print
Next

Set ind = Nothing
Set tdf = Nothing
Set db = Nothing
End Function
--
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.

"Filips Benoit" <be***********@pandora.be> wrote in message
news:Ve*****************@phobos.telenet-ops.be...
Dear All,

Is ( how) it possible to find the tablename of the table that is related
to
a field.

Field CLIENT_TITLE_ID is related to table TITLE

Thanks,

Filip

Nov 13 '05 #3
I created this function now using MSysRelationships.

************************************************** **************************
************
Public Function FindFieldRelatedTable(ByVal strTableName As String, ByVal
strFieldName As String) As String
On Error GoTo errHandling

Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Set conn = New ADODB.Connection
Set conn = CurrentProject.Connection

Set rs = New ADODB.Recordset
rs.Open "SELECT MSysRelationships.szReferencedObject FROM
MSysRelationships WHERE (((MSysRelationships.szObject)='" & strTableName &
"') AND ((MSysRelationships.szReferencedColumn)='" & strFieldName & "'));",
conn, adOpenForwardOnly, adLockReadOnly, adCmdText
FindFieldRelatedTable = rs.Fields(0).Value
rs.Close
Set rs = Nothing

Exit Function

errHandling:

MsgBox "Foutnr. " & Err.Number & " in functie FindFieldRelatedTable " &
Chr(13) & Err.Description
End Function
************************************************** **************************
******

"Filips Benoit" <be***********@pandora.be> wrote in message
news:Ve*****************@phobos.telenet-ops.be...
Dear All,

Is ( how) it possible to find the tablename of the table that is related to a field.

Field CLIENT_TITLE_ID is related to table TITLE

Thanks,

Filip

Nov 13 '05 #4
Unless I am missing something, you may need to provide more info.

Is your question: How do I determine the name of the table(s) joined to
table TITLE, where the from/to join field is CLIENT_TITLE_ID?

If so, query the System table, MSysRelationships:

SELECT MSysRelationships.szObject
FROM MSysRelationships
WHERE (((MSysRelationships.szReferencedObject)="TITLE") AND
((MSysRelationships.szReferencedColumn)="CLIENT_TI TLE_ID"));

Tony D'Ambra
Web Site: aadconsulting.com
Web Blog: accessextra.net
"Filips Benoit" <be***********@pandora.be> wrote in message
news:Ve*****************@phobos.telenet-ops.be...
Dear All,

Is ( how) it possible to find the tablename of the table that is related
to
a field.

Field CLIENT_TITLE_ID is related to table TITLE

Thanks,

Filip

Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Liam3 | last post by:
I'm having a problem with a table that accidently had a column added whose type is the same as the table. This is seriously creating a problem as I cannot delete the table and I really don't have...
2
by: Christian Höhener | last post by:
Hi I have a given attributvalue of a specific attribut (sys_obid=81653) which occurs in multiple tables. Now, I should know the tablename of the table in which this attribut occurs. Which...
1
by: Rehmann | last post by:
I have an Access front-end that has linked tables to an Oracle database; there are hundreds of linked tables in my front-end. Is there a way to write some code that goes through every table and...
1
by: Brian | last post by:
I'm trying to find a way to search multiple tables for the same record. Say I have 3 tables all with a name column, I need to search all 3 tables and find matching names. Is there an easy way to...
8
by: chippy | last post by:
Hi, I've a VB script that creates a Access object in a word doc. Here is the full script. It works for all but the Export. Which always fails with a 3011 error. If I do the same in Access as a...
3
by: Dag-Erling Smørgrav | last post by:
The PL/PGSQL documentation contains at least two examples of functions which take an argument of type "tablename", which then serves as a table name in a query. Here's one of those examples: >...
0
by: Ray | last post by:
Hi, I have upgraded my program from vb.net 2003 to vb.net 2005. In 2003, I can get the database name of tables of crystal report by the following code: For Each table In...
4
by: Mike Charney | last post by:
What is the easiest and simplest way to find out if a table exists in an Access Data Project? (SQL Svr 2000 Standard using MS-Access 2003 for connection.) Mike Charney m charney at dunlap...
7
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.