Microsoft KB Archive/161030

= ACC97: Invalid File Name Causes Untrappable Error in Assistant =

Article ID: 161030

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q161030



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



SYMPTOMS
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:  Open the sample database Northwind.mdb.  Create a module and type the following procedure: 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  With the module still open in Design view, click References on the Tools menu. 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. Click OK in the References dialog box. 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.</li></ol>

<div class="status_section">

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

<div class="moreinformation_section">

Steps to Reproduce Problem
<ol> Open the sample database Northwind.mdb.</li>  Create a module and type the following procedure: 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 </li> 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.</li></ol>

<div class="references_section">