Graham Charles
Posts: 13
Joined: 2005-07-29
|
Just to make things simple, I started from your Access example (accessexample_vb.zip). Adding any reference to ANY DAO OBJECT, as far as I can tell, causes Access to be unquittable. For example, if I change your toolbar item code to:
Private Sub AdxCommandBarButton1_Click(ByVal sender As Object) Handles AdxCommandBarButton1.Click
MessageBox.Show(AccessHost.CurrentDb.Name)
End Sub
I get the same problem.
How, exactly, can an add-in do anything useful if it can't access the application or its database that it's been added in to?
Thanks for your thoughts,
g. |
|
Sergey Grischenko
Add-in Express team
Posts: 7235
Joined: 2004-07-05
|
Hi Graham
The code below works fine on my PC. Could you please check it on yours?
Private Sub AdxCommandBarButton1_Click(ByVal sender As Object) Handles AdxCommandBarButton1.Click
Dim db As dao.Database = Nothing
Try
db = AccessHost.CurrentDb
MessageBox.Show(db.Name())
Finally
If Not (db Is Nothing) Then
Marshal.ReleaseComObject(db)
End If
End Try
'MessageBox.Show(AccessHost().Name)
End Sub |
|
Graham Charles
Posts: 13
Joined: 2005-07-29
|
Yes, that works fine. However, there's no way to pass that reference around, is there? I'm struggling to understand this limitation.
If I try to write generic code along the lines of
Public Function GetDatabaseOption(ByRef theDB As dao.Database, _
ByVal OptionName As String, _
Optional ByVal bCreate As Boolean = True) As String
...it will fail every time.
Can you explain the COM referencing issue? What exactly is going on with these references? Are they somehow being duplicated as they're marshalled across objects?
Thanks,
g. |
|
Sergey Grischenko
Add-in Express team
Posts: 7235
Joined: 2004-07-05
|
Hi Graham.
Can you send me the code? I will try to help. |
|
Graham Charles
Posts: 13
Joined: 2005-07-29
|
You know, I'm finding it easier to just do as much as possible through ADO.NET. (There was so little that I thought I'd avoid adding the dependency, but since I can't even generate a DAO.Recordset, it's just faster and less frustrating to do it this way.)
I'm still curious about why referencing an existing instance COM object increments the reference count, even when that reference falls out of scope. But only philiosphically -- practically speaking, I'm going to avoid DAO except as needed to retrieve the database path.
g. |
|