Ribbon tabs with Access 2007/2010...

Add-in Express™ Support Service
That's what is more important than anything else

Ribbon tabs with Access 2007/2010...
 
Heinz-Josef Bomanns




Posts: 206
Joined: 2008-02-28
Hi,

ADX 2010, VB.NET, Access-Add-In for 2007/2010 - i use an ADXRibbonTab, when opening Access the tab is shown even if no database is open. I just want the tab to be schown after a database has been opened. How to achieve this? Thanks for any hints...
__________________
Greetings, HJB
Posted 27 Sep, 2010 22:45:18 Top
Andrei Smolin


Add-in Express team


Posts: 16992
Joined: 2006-05-11
Hi HJB,

private AddinExpress.MSO.ADXAccessAppEvents adxAccessEvents;
private AddinExpress.MSO.ADXRibbonTab adxRibbonTab1;
private AddinExpress.MSO.ADXRibbonGroup adxRibbonGroup1;
private AddinExpress.MSO.ADXRibbonButton adxRibbonButton1;

private void adxAccessEvents_CloseDatabase(object sender, EventArgs e)
{
    DAO._DBEngine engine = AccessApp.DBEngine;
    DAO.Workspaces wkSpaces = engine.Workspaces;
    DAO.Workspace wkSpace = wkSpaces[0];
    DAO.Databases DBs = wkSpace.Databases;
    if (DBs.Count == 0) adxRibbonTab1.Visible = false;
    Marshal.ReleaseComObject(DBs);
    Marshal.ReleaseComObject(wkSpace);
    Marshal.ReleaseComObject(wkSpaces);
    Marshal.ReleaseComObject(engine);
}

private void AddinModule_OnRibbonBeforeCreate(object sender, string ribbonId)
{
    DAO._DBEngine engine = AccessApp.DBEngine;
    DAO.Workspaces wkSpaces = engine.Workspaces;
    DAO.Workspace wkSpace = wkSpaces[0];
    DAO.Databases DBs = wkSpace.Databases;
    if (DBs.Count == 0) adxRibbonTab1.Visible = false;
    Marshal.ReleaseComObject(DBs);
    Marshal.ReleaseComObject(wkSpace);
    Marshal.ReleaseComObject(wkSpaces);
    Marshal.ReleaseComObject(engine);
}

private void adxAccessEvents_OpenDatabase(object sender, EventArgs e)
{
    adxRibbonTab1.Visible = true;
}


Testing that code has produced a portion of new knowledge: DAO isn't prepared for non-released COM objects; if you omit Marshal.ReleaseComObject calls in the code above, Access 2010 won't close.

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 28 Sep, 2010 05:10:57 Top
Heinz-Josef Bomanns




Posts: 206
Joined: 2008-02-28
Hi Andrei,

thanks for the quick response and the solution - it works with 2010 but not with 2007. In 2007 the Ribbon upon startup is hidden, so that part is Ok. But when opening a database, the OpenDatabase event is fired and Visible is set to True but the Ribbon remains invisible. Any idea what may be different in 2007? Do you know by chance a way to invalidate the complete Access Ribbon, so i can force redrawing if my Ribbon?

And yes, Access and DAO is a pain in the a** when you treat it from within COM Add-Ins ;-) Spent hours and hours to get around ugly behaviours of Access and DAO...
__________________
Greetings, HJB
Posted 29 Sep, 2010 01:09:19 Top
Heinz-Josef Bomanns




Posts: 206
Joined: 2008-02-28
Hi Andrei,

while your solution is working with my Windows 7/Office 2010 installation, one of our betatesters, who also uses Windows 7/Office 2010, just reported that it is not working on his machine - the Ribbon is hidden upon startup und gets not visible when a database is open ;(
__________________
Greetings, HJB
Posted 29 Sep, 2010 05:21:04 Top
Andrei Smolin


Add-in Express team


Posts: 16992
Joined: 2006-05-11
Hi HJB,

I've tested the code in Access 2007; it works fine for me. What is the exact build number of your Access 2007?

As to your beta-tester's case, you need to check that the events do occur on his/her PC.

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 29 Sep, 2010 07:22:07 Top