'How can I get the the Microsoft Access Database Application Title via C#
I need to get the Application Title from an access database via C#. I have seen some samples using Office VBA: I.E: https://docs.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
Solution 1:[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
Solution 2:[2]
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());
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | dbmitch |
Solution 2 | Ian Guthrie |