Relation names

Z

zapcome

Hi guys, hope someone could help me with this one...

I have an Access database, which Im using in a program of mine...

I need to alter some tables and erase some foreign keys in a couple of
tables to make some processing... I already found out how to delete
them with DDL but I need the names of those relations to delete them...

Does anyone know which patterns Access follows to name those relations
between tables?

Thanks in advance!
 
R

RoyVidar

Hi guys, hope someone could help me with this one...

I have an Access database, which Im using in a program of mine...

I need to alter some tables and erase some foreign keys in a couple
of tables to make some processing... I already found out how to
delete them with DDL but I need the names of those relations to
delete them...

Does anyone know which patterns Access follows to name those
relations between tables?

Thanks in advance!

In these NGs, you will usually be recommended to use DAO for such...

Anyway, I think you can use the openschema method on an ADO connection
to retrieve the name of the relationship. Perhaps something along the
lines of the following air code, here assuming cn is initialized as
your ADO connection, and strTable contains the name of the table in
which this field is a foreign key (you can also pass the "primary key
table", as the third arguement - hit F1 on OpenSchema, and have a
look at the schemaenums).

set rs = cn.openschema(adschemaforeignkeys, _
array(empty, empty, empty, empty, empty, strTable))
do while not rs.eof
for lngCount = 0 to rs.fields.count-1
if not isnull(rs.fields(lngCount).value) then
debug.print rs.fields(lngCount).name, _
rs.fields(lngCount).value
end if
next lngCount
debug.print
rs.movenext
loop

the returned FK_NAME field, should contain the name
 
V

victorcamp

Relations can be enumerated via code. For example, this lists the name of
the first relationship:

? CurrentDb().Relations(1).Name

Check out the Help file for properties and methods of the Relations
collection, and the Relation object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top