[AccessD] Set references programmatically

Gustav Brock Gustav at cactus.dk
Mon Jul 24 10:34:45 CDT 2006


Hi Thomas

Here's one method:

' Include in Declarations:

  ' Length of GUID string per definition.
  Private Const clngGUID                As Long = 38

  Type GuidDefinition
    Guid As String * clngGUID
    Major As Integer
    Minor As Integer
  End Type

' Functions:

Public Function RefAddDao() As Boolean

  Dim typGuid As GuidDefinition
  
  With typGuid
    ' GUID for DAO. Don't specify version to add the latest.
    .Guid = "{00025E01-0000-0000-C000-000000000046}"
  End With
  
  RefAddDao = ReferenceAddFromGuid(typGuid)
  
End Function

Public Function ReferenceAddFromGuid(ByRef typGuid As GuidDefinition) As Boolean

' Add a reference from its GUID and verify it.
'
' 2001-08-20. Cactus Data ApS, CPH.


  ' Reference Guid not registered or registered with a lower version.
  Const clngErrorGuidNotRegistered As Long = -2147319779
  
  Dim ref         As Reference
  
  Dim booSuccess  As Boolean
  
  On Error Resume Next
  
  With typGuid
    References.AddFromGuid .Guid, .Major, .Minor
  End With
  
  If Not Err = clngErrorGuidNotRegistered Then
    ' The reference is registered but it may have been tampered with.
    ' Find it and check that it is not broken.
    For Each ref In References
      With ref
        If .BuiltIn = True Then
          ' no need to study built in references.
        ElseIf .Guid = typGuid.Guid Then
          ' This is the added reference.
          booSuccess = Not IsBroken97(ref)
          If booSuccess = True Then
            ' Return actual GUID version.
            typGuid.Major = .Major
            typGuid.Minor = .Minor
          End If
        End If
      End With
    Next
  End If
  
  Set ref = Nothing
  
  ReferenceAddFromGuid = booSuccess

End Function


Public Function IsBroken97(ByVal ref As Access.Reference) As Boolean

' Alternative method to check if a reference is broken
' as the IsBroken property cannot be used in Access97.
'
' 2000-03-19. Gustav Brock. Cactus Data ApS.

' Refer to this article at Microsoft Technet:
'
' Article ID: Q186720
'
' The information in this article applies to:
' Microsoft Access 97
'
' SYMPTOMS
' In Microsoft Access, IsBroken is a property of the References collection.
' The Microsoft Access Help topic on the Isbroken property states the following:
'
' The IsBroken property returns a Boolean value indicating whether a
' Reference object points to a valid reference in the Windows Registry.
'
' Although this statement is correct, to receive this Boolean value
' you must trap for errors that are generated by the broken reference.
' Also, the IsBroken property becomes True only when the file being referenced
' is deleted and the Microsoft Windows Recycle Bin is emptied.
' This article details the steps necessary to receive the Boolean value.

  Dim booRefOK As Boolean
  On Error GoTo Err_IsBroken97
  
  If Len(Dir(ref.FullPath, vbNormal)) > 0 Then
    booRefOK = Not ref.IsBroken
  End If

Exit_IsBroken97:
  IsBroken97 = Not booRefOK
  Exit Function

Err_IsBroken97:
  ' Ignore non existing servers, drives, and paths.
  Resume Exit_IsBroken97
  
End Function


/gustav

>>> ewaldt at gdls.com 24-07-2006 14:16:08 >>>

I create smaller databases from a main one so that I can send out the
smaller ones to users. I export forms, queries, and appropriate subsets of
tables. I also export a startup macro and a VBA function for the startup
macro to run. Now for the problem.

The VBA function uses DAO, and I need to make sure the user will have DAO
referred to. How do I do that programmatically? Specifically, I am looking
for "Microsoft DAO 3.6 Object Library".

TIA,

Thomas F. Ewald
FCS Database Manager
General Dynamics Land Systems
(586) 276-1256





More information about the AccessD mailing list