Load References through VBA?

Posted on 2003-03-26
Medium Priority
Last Modified: 2008-05-22

Any idea how I can programmatically encoded my ACCESS mdb application to automatically load the appropriate reference object library automatically (if it is not already loaded) when the user start the application?  I assume that the code will need to handle different library folder installed on different computers, too?  

Question by:bunsongsikult
  • 3
LVL 18

Accepted Solution

1William earned 500 total points
ID: 8211136
Take a look at this code,  It should get you moving in the right direction:
Public Sub FixUpRefs()
Dim loRef As Access.Reference
Dim intCount As Integer
Dim intX As Integer
Dim blnBroke As Boolean
Dim strPath As String

On Error Resume Next

    '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)
      With loRef
        blnBroke = .IsBroken
        If blnBroke = True Or Err <> 0 Then
          strPath = .FullPath
          With Access.References
            .Remove loRef
            .AddFromFile strPath
          End With
        End If
       End With
End Sub

Public Sub ReferenceInfo()
Dim strMessage As String
Dim strTitle As String
Dim bytButtons As Byte
Dim refItem As Reference

On Error Resume Next

    For Each refItem In References
        If refItem.IsBroken Then
            strTitle = "MISSING Reference"
            strMessage = "Missing Reference:" & vbCrLf & refItem.FullPath
            bytButtons = 16 'critical symbol
            ' You could here try to fix the reference
            '   Check to see if the required file is on the PC
            '       Not there?  Add it from a specified network location
            '   Fix the reference
            strTitle = "Displaying References and Their Locations"
            strMessage = "Reference: " & refItem.Name & vbCrLf & _
            "Location: " & refItem.FullPath
            bytButtons = 64 'information symbol
        End If

      MsgBox prompt:=strMessage, Title:=strTitle, buttons:=bytButtons

    Next refItem

End Sub
LVL 18

Expert Comment

ID: 9054185
I take it the provided code got you going.  glad to of resolved the issue.  :)
LVL 18

Expert Comment

ID: 9239475
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept question, points to 1William
Please leave any comments here within the next seven days.


EE Cleanup Volunteer

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question