ACC97: Invalid File Name Causes Untrappable Error in Assistant

ID: Q161030


The information in this article applies to:
  • Microsoft Access 97


SYMPTOMS

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

If you set an invalid FileName property for the Assistant object in Visual Basic for Applications code, a trappable run-time error does not occur until you click Cancel in the message box that appears.


RESOLUTION

You can use the FileSearch object to determine if the Assistant file exists before you set the FileName property in code. The following sample code uses the FileSearch object to search for the Assistant file before you set the FileName property:

  1. Open the sample database Northwind.mdb.


  2. Create a module and type the following procedure:


  3. 
          Sub SetAssistant(ActFile as String)
             On Error GoTo SetAssistant_Err
             Dim fs As FileSearch
             Dim accObj as Object
             Dim i As Integer
    
             ' Search for the Assistant file name.
             Set fs = Application.FileSearch
             With fs
                .LookIn = "C:\"
                .SearchSubFolders = True
                .FileName = ActFile
                If .Execute > 0 Then
                   Set accObj = CreateObject("Access.Application")
                   With accObj
                      .Visible = True
                      .Assistant.FileName = ActFile
                      .Assistant.Visible = True
                   End With
                Else
                   MsgBox "The Assistant file you specified was not found."
                End If
             End With
             GoTo SetAssistant_Exit
          SetAssistant_Exit:
             Set fs = Nothing
             Set accObj = Nothing
             Exit Sub
          SetAssistant_Err:
             MsgBox Err.Number
             Resume SetAssistant_Exit
          End Sub 
  4. With the module still open in Design view, click References on the Tools menu.


  5. In the References dialog box, click Microsoft Office 8.0 Object Library in the Available References box. If that reference does not appear, click the Browse button and browse your hard drive for MSO97.DLL.


  6. Click OK in the References dialog box.


  7. To test the procedure, type the following line in the Debug window, and then press ENTER:
    SetAssistant("clippit.act")
    If Clippit.act exists on your computer, an instance of Microsoft Access starts, shows the Assistant, and then quits. If the file does not exist, you receive an error message and the procedure stops.



STATUS

Microsoft has confirmed this to be a problem in Microsoft Access 97.


MORE INFORMATION

Steps to Reproduce Problem

  1. Open the sample database Northwind.mdb.


  2. Create a module and type the following procedure:


  3. 
          Sub Test()
             On Error GoTo Err_Occurred
             Dim accObj As Object
             Set accObj = CreateObject("Access.Application")
             accObj.Assistant.FileName = "NonExistent.act"
          Exit Sub
    
          Err_Occurred:
          MsgBox "The following error occurred: " & vbcr & Err.Number
    
          End Sub 
  4. To test this function, type the following line in the Debug window, and then press ENTER:
    Test
    Note that an instance of Microsoft Access starts, and the Office Assistant displays an error message indicating that the file does not exist. The procedure stops executing until you click Cancel in the Assistant message box. Then the error passes to your error handling code.



REFERENCES

For more information about programming with the Office Assistant, search the Help Index for "Assistant object."

Additional query words: OLE Automation

Keywords : kberrmsg AccCon IntpOlea
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbbug


Last Reviewed: September 30, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.