Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 348
  • Last Modified:

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.

  • 4
  • 3
1 Solution
in MS-ACCESS press the "Relationships" button and from there you can delete/modify ang relationships you want.
BobsExExAuthor Commented:

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.

im not really with DAO... why not use ADOX then?  ADO and DAO can exist together anyway in one code...
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

BobsExExAuthor Commented:

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)

BobsExExAuthor Commented:
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.

PAQ'd and points refunded

Community Support Moderator @Experts Exchange
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\" & _

    ' 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...

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now