Link to home
Start Free TrialLog in
Avatar of BobsExEx
BobsExEx

asked on

Modify a Relation in MS Access / DAO


I am now coding in VB6/DAO (not my idea).

Any ideas on how to modify the attributes of a relation in MS Access?

I would like to remove the attributes for a bunch of relations.  They are now:

dbRelationDeleteCascade + dbRelationUpdateCascade

and I would like to remove them and have the default attributes.

Thanks
Bob
Avatar of earlnoli
earlnoli

in MS-ACCESS press the "Relationships" button and from there you can delete/modify ang relationships you want.
Avatar of BobsExEx

ASKER


I appreciate the feedback.  This is something that I need to do through VB Code using DAO because there are many databases that this will be used on.

Bob
im not really with DAO... why not use ADOX then?  ADO and DAO can exist together anyway in one code...

Well I am in VB6 - isn't ADOX .NET?  Do you know a way of doing it in regular ADO?
actually ADOX is a part of ADO that deals with table manipulation and such... u cant create a table using ADO, u have to use ADOX... this is actaully the reason ADO is better than DAO, bec it separated its components making it less resource hungry.  But since u specify u need to modify relationships via code, the only way to do it via ADO is using ADOX...

Normally using ADO, you reference...

-Microsoft ActiveX Data Objects 2.5 Library

To use ADOX to manipulate tables and relationships via code... use...

-Microsoft ADO Ext. 2.5 for DLL and Security (this is what im using now, and it depends on what Version of MDAC you currently have)

I am not sure if you are correct on that.  I usually use ADO and can do anything in there I want with db.execute and I always just use "Microsoft ActiveX Data Objects 2.6 Library".

I am now using DAO because I am working at a new job and here, they only want to use DAO because they are familiar with it, are transitioning from VB to Java (so it won't be an issue anymore), and don't need the problems caused by the small nuances of changing from DAO to ADO (I don't care either way, really).

In any case, what I ended up doing was going through the  DAO db.relations collection, pulling out the .Name, .Table, .ForeignTable, .Field(0).name, and .Field(0).ForeignName values, then deleting the relation with db.Relations.Delete .Name, and then immediately recreating the relation with the same values but with no attributes specified.

Thanks for the attempt, though.

Bob
ASKER CERTIFIED SOLUTION
Avatar of SpideyMod
SpideyMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ah... ic... no problem then...
but im still sure about the ADOX stuff about table manipulation and relationship definition... if u dont believe me... this is a cut and paste defintion of ADOX from the ADO help file... they are just located in one help file together with ADOMD

anyway this is heading of ADOX..

Microsoft® ActiveX® Data Objects Extensions for Data Definition Language and Security (ADOX) is an extension to the ADO objects and programming model. ADOX includes objects for schema creation and modification, as well as security. Because it is an object-based approach to schema manipulation, you can write code that will work against various data sources regardless of differences in their native syntaxes.

ADOX is a companion library to the core ADO objects. It exposes additional objects for creating, modifying, and deleting schema objects, such as tables and procedures. It also includes security objects to maintain users and groups and to grant and revoke permissions on objects.


--------
anyways this is an example how u can create a relationhip on ADOX... which you cant do in ADO alone...


Sub CreateKey()

    Dim kyForeign As New ADOX.Key
    Dim cat As New ADOX.Catalog

    ' Connect the catalog
    cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=c:\Program Files\Microsoft Office\" & _
        "Office\Samples\Northwind.mdb;"

    ' Define the foreign key
    kyForeign.Name = "CustOrder"
    kyForeign.Type = adKeyForeign
    kyForeign.RelatedTable = "Customers"
    kyForeign.Columns.Append "CustomerId"
    kyForeign.Columns("CustomerId").RelatedColumn = "CustomerId"
    kyForeign.UpdateRule = adRICascade
   
    ' Append the foreign key
    cat.Tables("Orders").Keys.Append kyForeign
   
    'Delete the Key as this is a demonstration
    cat.Tables("Orders").Keys.Delete kyForeign.Name
End Sub

---

I hope this clarifies some of ur notions of ADO... DAO sucks bec its all in one package... sometimes you just want to take what you want to use... less network footprint... faster...