2

I need to get the Application Title from an access database via C#. I have seen some samples using Office VBA: I.E: https://learn.microsoft.com/en-us/office/vba/api/access.application.apptitle

The issue is that I don't have a reference to a class library to be able to access the Application.AppTitle property. I have tried a few references, most notably:

using Microsoft.Office.Interop.Access.Dao

But I can't access the Application.AppTitle via any of the properties. For example:

  var dbe = new Microsoft.Office.Interop.Access.Dao.DBEngine();
        var db = dbe.OpenDatabase(@"c:\\Sample.mdb");

        // Show database properties
       // db.Properties. "When I expand this there is no AppTitle"

Does anyone have any other approach that has worked for them to access the MS Access AppTitle via C#?

Thanks in advance!

Ian

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45

3 Answers3

1

The AppTitle property doesn't show up until you set it in Access or via code (and with RefreshTitleBar

Your code works because you're looping to check for the name. You won't find the property if it's empty.

You can use the loop method like you do above or check for it directly using database.properties("AppTitle") - just make sure you trap for an error in case it's empty

App Title property

dbmitch
  • 5,361
  • 4
  • 24
  • 38
  • As a follow up question, do you know of any other way to do this in C# other than using: using Microsoft.Office.Interop.Access.Dao? It seems that Dao has been depreciated, but I haven't seen any other classes that allow direct access to AppTitle the same way.. – Ian Guthrie May 13 '22 at 19:02
  • 2
    DAO hasn't been deprecated. They reversed their position and now approve DAO over ADO. – dbmitch May 13 '22 at 20:37
  • Nah, DAO is straight garbage because of this: https://www.codeproject.com/Questions/1081085/Access-dao-dbengine-dependency-issues-in-net I am hitting the same class not registered issue, so it's still a major bug. – Ian Guthrie May 14 '22 at 01:44
  • DAO is still in use and favored - it's been superseded by Access Database Engine object (ACE) - ACE gives you both use of the database engine (ACE) and a “DAO” library. So only one reference is required now in Access to use the database engine + DAO code. – dbmitch May 14 '22 at 18:36
0

Update: I figured it out. This was different than I expected, but the solution was:

 var dbEngine = new DBEngine();
        var database = dbEngine.OpenDatabase(@"c:\\Sample.mdb");

        Microsoft.Office.Interop.Access.Dao.Property allowBypassKeyProperty = null;

        foreach (Microsoft.Office.Interop.Access.Dao.Property property in database.Properties)
        {
            if (property != null)
            {
                if (property.Name == "AppTitle")
                {
                    MessageBox.Show(property.Name.ToString());
                    MessageBox.Show(property.Value.ToString());
                }
            }


        }
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 14 '22 at 01:22
0
db.Properties["AppTitle"].Value.ToString()
blackgreen
  • 34,072
  • 23
  • 111
  • 129
nonlinear
  • 33
  • 7