Access add-in: Database won't compress after accessing it via code...

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

Access add-in: Database won't compress after accessing it via code...
 
Heinz-Josef Bomanns




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

ADX latest version, Access 2002-2010: A database is set to compress automatically on exit. After running a dialog from the add-in and leaving the database i get an error 'Database is exclusivelly opened by user X on machine Y...' and the database won't compress. The dialog accesses the current database to fill a combobox with the names of tables like this:

Dim db As dao.Database = Nothing, tds As dao.TableDefs = Nothing, td As dao.TableDef = Nothing

  db = AddinModule.CurrentInstance.HostApplication.CurrentDB() 'Access Application
  tds = db.TableDefs
  With clAccTables
    .Items.Clear()
    .Items.Add("<Choose table>")
    For Each td In tds
      If Not td.Name.StartsWith("MSys") And Not td.Name.StartsWith("USys") Then
        .Items.Add(td.Name)
      End If
    Next 'td
    .SelectedIndex = 0
  End With 'clAccTables
  Marshal.ReleaseComObject(td) : td = Nothing
  Marshal.ReleaseComObject(tds) : tds = Nothing
  Marshal.ReleaseComObject(db) : db = Nothing

As you see i release all object variables i use, so there should be no open references that prevent the database from automatically compressing. If i don't open the dialog, i don't get this error. Any ideas or hints whats going wrong here? Thanks...

PS: If testing this you'll have to alter at least one record to give Access a reason to do the compressing...
__________________
Greetings, HJB
Posted 20 Feb, 2012 00:15:58 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Heinz-Josef,

Where does the clAccTables object come from? Anyway, please note that you don't release the Items collection. Please read more about this in the When to release COM objects in Office add-ins developed in .NET article on our technical blog.
.NET, Extended MAPI, Windows Phone & RT
Posted 20 Feb, 2012 03:23:30 Top
Heinz-Josef Bomanns




Posts: 201
Joined: 2008-02-28
Hi Eugene,

clAccTables is a combobox that just holds some strings (names of the Access tables), no objects, so Items can't/won't have to be released. Mentioned article i've readed several times since working with ADX and all tips & hints has been followed - all used object variables i've declared and used are relaesed afterwards. Any other ideas? Thanks...
__________________
Greetings, HJB
Posted 22 Feb, 2012 03:08:07 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Heinz-Josef,

The article I mentioned above doesn't recommend using the For Each loop with COM objects. For example:

For Each td In tds 


Do you release the td object each time?
.NET, Extended MAPI, Windows Phone & RT
Posted 22 Feb, 2012 03:22:43 Top
Heinz-Josef Bomanns




Posts: 201
Joined: 2008-02-28
Hi Eugene,

thanks, will try that and let you know...
__________________
Greetings, HJB
Posted 25 Feb, 2012 12:59:03 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Heinz-Josef,

Please keep me notified.
.NET, Extended MAPI, Windows Phone & RT
Posted 26 Feb, 2012 10:25:24 Top