Link to home
Start Free TrialLog in
Avatar of jaimexctsg
jaimexctsg

asked on

How to make sure that my Access 2000 mdb will reference DAO 3.6

I need to make sure that my Access 2000 mdb will reference DAO 3.6 wherever it is.
Here is the scenario:
I create an mdb, lets call it original.mdb. It need a reference to "Microsoft DAO 3.6". I go to the modules, open one of them, go to references, add the reference, and compile the whole thing. Now my original.mdb has a reference to "Microsoft DAO 3.6". So far so good.

Next, I create a new.mdb and import everything from the original.mdb. The problem is that now, my new.mdb does not have the references to "Microsoft DAO 3.6".

What can I do to make sure I will always have that reference wherever and whenever I impoort the objects from the original mdb?  Is this possible?

Thanks to all in advance.
Avatar of rockiroads
rockiroads
Flag of United States of America image

you could always use the VBA code which refreshes references, give that a try

Public Sub Install_RefreshReferences()
   
    Dim loRef As Object
    Dim iNoOfRefs As Integer
    Dim iCnt As Integer
    Dim bIsBroke As Boolean
    Dim strPath As String
    Dim bBroke As Boolean
   
    On Error Resume Next
   
   
    Err.Clear

    'Count the number of references in the database
    iNoOfRefs = Application.VBE.ActiveVBProject.References.Count
   
    'Loop through each reference in the database and determine if the reference is broken.
    'If it is broken, remove the Reference and add it back.
    For iCnt = iNoOfRefs To 1 Step -1
       
        Set loRef = Application.VBE.ActiveVBProject.References(iCnt)
        Debug.Print loRef.Name, loRef.FullPath
       
        'Dont do Application.VBE.ActiveVBProject.References
        With loRef
           
            bIsBroke = .IsBroken
            If bIsBroke = True Or Err <> 0 Then
               
                Err.Clear
                strPath = .FullPath
                Debug.Print strPath
               
                With Application.VBE.ActiveVBProject.References
                    .Remove loRef
                    If Err.Number > 0 Then
                        If Err.Number <> 57101 Then  'Cant remove default reference
                            Debug.Print "Removal Failure (" & Err.Number & ") : " & Err.Description
                            MsgBox "Reference Removal Failure (" & Err.Number & ") : " & Err.Description, vbCritical, "Refresh Refs"
                        End If
                        Err.Clear
                    Else
                        .AddFromFile strPath
                        If Err.Number > 0 Then
                            Debug.Print "Insert Failure (" & Err.Number & ") : " & Err.Description
                            MsgBox "Reference Insert Failure (" & Err.Number & ") : " & Err.Description, vbCritical, "Refresh Refs"
                        End If
                        Err.Clear
                    End If
                End With
            End If
        End With
    Next
   
    Set loRef = Nothing
   
    Exit Sub
   
rrError:
    MsgBox "Error " & Err.Number & " trapped." & vbCrLf & Err.Description, vbCritical, "Refresh Refs"
End Sub
Avatar of Mourdekai
Mourdekai

Here's a function I wrote for another question similar to this, maybe it can help:

Call this function, if it (DAO 3.6) is broke it will fix it, it is already there it does nothing, and if it is missing it will add it.

Function CheckDAO()
On Error Resume Next
   Dim refItem As Reference
   Dim blnLoaded As Boolean

   blnLoaded = False
   For Each refItem In References
       If refItem.Guid = "{00025E01-0000-0000-C000-000000000046}" Then
           'The refItem is DAO
           If refItem.IsBroken Then
               With Access.References
                   Debug.Print "DAO 3.6 is broken"
                   'remove it
                   .Remove refItem
                   'add it back
                   .AddFromGuid "{00025E01-0000-0000-C000-000000000046}", 5, 0
                   blnLoaded = True
               End With
           Else
               Debug.Print "DAO 3.6 Already loaded"
               blnLoaded = True
           End If
       End If
   Next refItem
   
   If blnLoaded = False Then
       Debug.Print "DAO 3.6 wasn't there so we added it"
       'It wasn't there, so we add it now
       Access.References.AddFromGuid "{00025E01-0000-0000-C000-000000000046}", 5, 0
   End If

End Function
Avatar of jaimexctsg

ASKER

I will try both, but I am more inclined to use Mourdekai 's code.m The problem is that this will be distributed and I want to make sure the client does not get an error message fron Access, since he wont have the tools to fix it.
Sorry to look so dumb, but I could not get it to work. If my mdb does not have the reference to DAO, i cannot start it. I receive a compiler error: "user-defined type not defined".
i need this DAO360.dll to be referenced by the mdb, from code, no matter what. i could even include it in the distribution package, because it goes as an Access 2000 RT application.
Is it possible from code to make the reference happen?
Thanks again
ASKER CERTIFIED SOLUTION
Avatar of Mourdekai
Mourdekai

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
both sets of code need to be run in code

mine is slighly different, it checks ALL missing references and corrects them

Actually, Ive realised Ive given you the wrong one, I have two, one for Excel and one for Access, Excel works slightly differently, sorry about that

here is the access one, pass in TRUE to refresh all, FALSE to refresh broken refs only


Public Sub Install_RefreshReferences(Optional ByVal bByPassBroke As Boolean = False)
   
    Dim loRef As Access.Reference
    Dim intCount As Integer
    Dim intX As Integer
    Dim blnBroke As Boolean
    Dim strPath As String
    Dim bBroke As Boolean
   
    'on error resume next
   
   
    Err.clear

    'Count the number of references in the database
    intCount = Access.References.Count
   
    'Loop through each reference in the database and determine if the reference is broken.
    'If it is broken, remove the Reference and add it back.
    For intX = intCount To 1 Step -1
       
        Set loRef = Access.References(intX)
        Debug.Print loRef.Name, loRef.FullPath
       
        'Dont do Access
        With loRef
           
            If bByPassBroke = False Then
                blnBroke = .IsBroken
                If blnBroke = True Or Err <> 0 Then
                    bBroke = True
                Else
                    bBroke = False
                End If
            Else
                bBroke = True
            End If
           
            If bBroke = True Then
                Err.clear
                strPath = .FullPath
                With Access.References
                    .Remove loRef
                    If Err.Number > 0 Then
                        If Err.Number <> 57101 Then  'Cant remove default reference
                            Debug.Print "Removal Failure (" & Err.Number & ") : " & Err.Description
                            MsgBox "Reference Removal Failure (" & Err.Number & ") : " & Err.Description, vbCritical, "Refresh Refs"
                        End If
                        Err.clear
                    Else
                        .AddFromFile strPath
                        If Err.Number > 0 Then
                            Debug.Print "Insert Failure (" & Err.Number & ") : " & Err.Description
                            MsgBox "Reference Insert Failure (" & Err.Number & ") : " & Err.Description, vbCritical, "Refresh Refs"
                        End If
                        Err.clear
                    End If
                End With
            End If
        End With
    Next
   
    Set loRef = Nothing
   
    MsgBox "References have been refreshed", vbInformation, APP_TITLE
    Err.clear
   
    Exit Sub
   
rrError:
    MsgBox "Error " & Err.Number & " trapped." & vbCrLf & Err.Description, vbCritical, APP_TITLE
End Sub

Sorry I haven't answered yet, I got mixed up with about four diferent security.mdw's for about seventeen diferent mdb's. Even though I know all the passwords it is a mess in here. Will get back to you as soon as I can .
Thanks for the points!