Change DAO3.5/3.6 reference while runtime? 
Author Message
 Change DAO3.5/3.6 reference while runtime?


to let the users of my word97 addin pick some data from access, I referred to DAO3.5. But some of them
might use Access2000 with Unicode entries (and word97 IS able to show them with its userforms!) so that I
have to referr to DAO3.6. I can't referr to DAO3.5 by default because of those who don't have Access2000.
Surely I will not set the either reference while design time because this would force two versions to

I tried something like the following    (set references to "DAO3.5" and "MS-VBA Extensibility"!)

Sub Startme()

    'now do something like
    'Dim DB as Database
    'Set DB = Opendatabase("MyAccess2000.mdb",false,false)
    'MsgBox DB.Name     'this fails with DAO3.5!
End Sub

Function DAO36Installiert() As Boolean
    DAO36Installiert = True     'originally testing a registry key
End Function

Sub DAO_Wechseln(wovon As Document)
    Dim myRef As Reference
    Dim allRefs As References
    Dim daoGUID As String
    Dim daoMajor As Long, daoMinor As Long
    Dim wiegespeichert As Boolean

    wiegespeichert = wovon.Saved
    daoGUID = "{00025E01-0000-0000-C000-000000000046}"
    daoMajor = IIf(VersionDAO = "3.6", 5, 4)
    daoMinor = 0

    Set allRefs = wovon.VBProject.VBE.ActiveVBProject.References
    ReDim Links(allRefs.Count, 2)
    For Each myRef In allRefs
        MsgBox "vorher Referenz:" & vbCrLf & _
            myRef.Name & "/" & myRef.Description & " in " & wovon.Name
        If myRef.GUID = daoGUID Then 'erste und einzige Referenz akzeptieren!
            If myRef.Major <> daoMajor Then
                If daoMajor = 5 Then
                    If DAO36Installiert() Then  
                        allRefs.Remove myRef
                    End If
                End If
            End If
            Exit For
        End If

    On Error Resume Next
    If DAO36Installiert() Then
        allRefs.AddFromGuid daoGUID, daoMajor, daoMinor
    End If

    'only to check it
    For Each myRef In allRefs
        If myRef.GUID = daoGUID Then
            MsgBox "hinterher Referenz: " & myRef.Name & "/" & myRef.Description
            Exit For
        End If
    wovon.Saved = wiegespeichert
End Sub


That looks good and SEEMS to work, BUT: though the reference is said to be changed IT IS NOT! Obviuosly
word keeps the old one in mind especially if it has been used once.

Anyone got an idea how to really change a DAO reference while runtime?

By the way: if I saved the addin after changing the reference with the above code, everything would be
fine with the next start of winword. But you all know that this will let grow the file size immediately
(from 1 MB to about 1.5 MB, and 1.9 MB the next time...)!

Thanx, Lorenz

Sat, 31 Aug 2002 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. dao 3.6 reference lost on closing database

2. Reference DAO 3.6 Object Library or DAO 2.5/3.51 Compatibility Library

3. DAO 3.6 changes from 3.5

4. Changing Field Properties via ADO 3.6

5. Changing Field Properties via DAO 3.6

6. Null behavior change from ODBC 3.0 to 3.6

7. Changing Field Properties via DAO 3.6

8. Referencing DAO 3.51 and DAO 3.60

9. References to MS DAO 3.51, 3.60, 2.5

10. What changes my OCX reference to and OCA reference

11. DAO 3.6 bookmark problem

12. VB4 and DAO 3.6 Update method Compile Error


Powered by phpBB® Forum Software