Microsoft KB Archive/109738

{|
 * width="100%"|

ACC1x: Trapping for Library Being Opened Before Database

 * }

Q109738

-

The information in this article applies to:


 * Microsoft Access versions 1.0, 1.1

-

SUMMARY
If you try to open a Microsoft Access library without first opening a database, the following error message is displayed:

A Run-Time error occurred in Database: . You don't have permission to view the Modules in this Database.

This article discusses a technique for handling this situation using error trapping in Access Basic.

This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information on Access Basic, please refer to the "Introduction to Programming" manual.

MORE INFORMATION
You can have a function in your Library determine whether a database is open by trapping for an error. For example, if a function in the library tries to open a form without a database first being opened, error number 2046 will be returned with the error message "Command Not Available: OpenForm."

You can trap this error message and display a more useful error message using the method demonstrated in the following sample error handler:

  On Error GoTo Errhand

Errhand: 'Display error number with error meaning MsgBox "Error # - " & Str(Err) & " - " & Error$

If Err = 2046 Then 'Display user-customized error message MsgBox "Please open a database first" Exit Function End If