Solved

Excel VB.net/VSTO - Get Table relationships in Access database

Posted on 2013-12-09
4
687 Views
Last Modified: 2013-12-10
Hi

I am using the following code to open an Access database from my Excel
Add-in project. I want to find the table relationships using code similar to the
VBA code that I found between the lines in the middle.
How would I do this?


    Sub Import_CSV_to_Access_table()
        Try

            Dim arrSplit As Object = Split(Globals.ThisAddIn.oRIGHT.lblConnectionString.Text, "=")
            Dim Access_File_Path As String = Mid(arrSplit(2), 1, Len(arrSplit(2)) - 1)

            Dim appAccess As New Microsoft.Office.Interop.Access.Application
            appAccess.OpenCurrentDatabase(Access_File_Path)
            appAccess.Visible = True

            appAccess.DoCmd.SetWarnings(False)
            Dim oAccessDB As Microsoft.Office.Interop.Access.curr


            '----------------------------------------------------------------------
            For Each rel In db.Relations
                Debug.Print(rel.Name, rel.Table, rel.ForeignTable, rel.Attributes)
                For Each fld In rel.Fields
                    Debug.Print, fld.Name, fld.ForeignName
                Next
            Next
            '----------------------------------------------------------------------

            appAccess.DoCmd.SetWarnings(True)

            appAccess.CloseCurrentDatabase()
            appAccess.Quit()
            appAccess = Nothing

        Catch ex As Exception
            MsgBox(ex.Message & " poph11")
        End Try
    End Sub
0
Comment
Question by:murbro
  • 2
  • 2
4 Comments
 
LVL 34

Expert Comment

by:PatHartman
ID: 39706360
I gave you an answer in your other post.

Please don't post multiple versions of the same question or if you do, at least tell us and paste a link.
0
 

Author Comment

by:murbro
ID: 39707967
Hi

But this is via VB.net. Please could you post the rest of the VB.net code required to connect to the database and run your query SELECT MSysRelationships.*
FROM MSysRelationships;
0
 
LVL 34

Accepted Solution

by:
PatHartman earned 500 total points
ID: 39708581
This is an Access forum.  If you need code for VB.net, you would be better off posting your request there.  The query I suggested is like any other query you would run from vb.net against Jet/ACE tables.  The only difference is that it queries a system table.  If you open the database and don't see the MSys tables, you can show them by right-clicking on the header of the navigation pane and choosing "Navigation Options".  Then click the box that says "Show System Objects".  The tables don't need to be visible for the query to work.
0
 

Author Closing Comment

by:murbro
ID: 39708639
Thank you for the last comment. It helped a lot
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now