ACC1x: Trapping for Library Being Opened Before Database

ID: Q109738


The information in this article applies to:


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: <Library Name>. 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 


REFERENCES

Microsoft Access "Introduction to Programming," version 1.0, Chapter 6, "Handling Run-Time Errors," pages 69-78

For more information on libraries, search for "library databases" then "Customizing MSACCESS.INI Settings" using the Microsoft Access Help menu.


Keywords          : kberrmsg kbprg MdlLib PgmErr 
Version           : 1.0 1.1
Platform          : WINDOWS 
Issue type        : kbinfo 

Last Reviewed: April 2, 1999