ACC1x: Trapping for Library Being Opened Before DatabaseID: Q109738
|
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.
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
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