ACC97: How to Force the IsBroken Property to Return True (186720)



The information in this article applies to:

  • Microsoft Access 97

This article was previously published under Q186720

SYMPTOMS

Advanced: Requires expert coding, interoperability, and multiuser skills.

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.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

RESOLUTION

If you want to force the IsBroken property to return True, you must first trap the standard error message, and then use the IsBroken property.

MORE INFORMATION

To create an example so that IsBroken returns True, you must first create a broken reference. If you create a reference to an ActiveX control or any other library that has its own registry entry and the referenced library is deleted, you will see a standard error message when trying to use the IsBroken property. IsBroken is not able to return True to the Visual Basic for Applications procedure until the standard messages are masked with error trapping. If you do not trap for errors before using IsBroken in the second example, you will receive the following message:

Runtime Error 48: Error in Loading DLL

To create a broken reference for an ActiveX Control, follow these steps:

  1. Start Microsoft Access and create a new blank database named DB1.mdb.
  2. Create a new report based on any table or query.
  3. On the Insert menu, click ActiveX Control.
  4. Click "Snapshot Viewer Control, version 8.0," and then click OK.
  5. Close the report. Do not save the changes.
  6. Close the database.
  7. Quit Microsoft Access.
  8. Locate the Snapshot Viewer Control file, Snapview.ocx, in the \Windows\System folder (or in the \Winnt\System32 folder if you are using Microsoft Windows NT) and delete the file. Then, empty the Microsoft Windows Recycle Bin.
  9. Restart Microsoft Access and open DB1.mdb, which you created in step 1.
  10. Create a new module.
  11. Type the following code in the new module:
            Public Function IsBrokenProperty()
    
            Dim ref As Reference
    
              ' Enumerate through References collection.
              For Each ref In References
              ' Check IsBroken property.
              On Error GoTo errorhandler:
                 If ref.IsBroken = True Then
                 ' Print the name of the reference and the fact that it is
                 ' broken.
                     Debug.Print ref.Name & " is broken"
                 End If
              Next ref
    
            Exit Function
    
            errorhandler:
    
            ' If the error received is 48 it's an error from the broken
            ' reference. Print the reference the fact it's broken and path to
            ' the Debug window.
            If Err.Number = 48 Then
               Debug.Print "Reference broken for: " & ref.FullPath
            End If
    
          End Function
    					
  12. On the Debug menu, click Compile Loaded Modules.
  13. Save the Module as CheckIsBroken.
  14. Press CTRL+G to open the Debug window.
  15. Type the following in the Debug window, and then press ENTER:
    ?IsBrokenProperty ()
    						
    Note that in the Debug Window you receive one of the following messages, depending on your operating system:
           Reference broken for: C:\WINDOWS\SYSTEM\SNAPVIEW.OCX
    
            -or-
    
           Reference broken for: C:\WINNT\System32\SNAPVIEW.OCX
    					
NOTE: If you have a reference to another Microsoft Access database and then delete the referred database, you can use a simple IF statement with the IsBroken property and the property will return True.

Modification Type:MinorLast Reviewed:9/13/2006
Keywords:kbprb kbProgramming KB186720