Error Trapping – Err Number- Visual Basic for Applications

On Error Statement

The On Error statement causes Visual Basic for Applications to start or stop error trapping.
The On Error statement also specifies a set of statements to execute if an error is encountered.

Err Function

The Err function returns the number of the error encountered.

Msgbox “The most recent error number is ” & Err & _
“. Its message text is: ” & Error(Err)

The following table contains a list of the trappable error codes you may encounter when you use the Err function.

Error code Error message
———- ————-
3 Return without GoSub
5 Invalid procedure call
6 Overflow
7 Out of memory
9 Subscript out of range
10 Duplicate definition (versions 5.0 and 7.0)
10 This array is fixed or temporarily locked (version97)
11 Division by zero
13 Type mismatch
14 Out of string space
16 String formula too complex (versions 5.0 and 7.0)
16 Expression too complex (version 97)
17 Can’t perform requested operation
18 User interrupt occurred
20 Resume without error
28 Out of stack space
35 Sub or function not defined (versions 5.0 and 7.0)
35 Sub, function, or property not defined (version 97)
47 Too many DLL application clients (version 97)
48 Error in loading DLL
49 Bad DLL calling convention
51 Internal error
52 Bad file name or number
53 File not found
54 Bad file mode
55 File already open
57 Device I/O error
58 File already exists
59 Bad record length
61 Disk full
62 Input past end of line
63 Bad record number
67 Too many files
68 Device unavailable
70 Permission denied
71 Disk not ready
74 Can’t rename with different drive
75 Path/File access error
76 Path not found
91 Object variable not set (versions 5.0 and 7.0)
91 Object variable or With block variable not set
(version 97)
92 For Loop not initialized
93 Invalid pattern string
94 Invalid use of Null
95 User-defined error (versions 5.0 and 7.0 only)
298 System DLL could not be loaded (version 97)
320 Can’t use character device names in specified file names
(version 97)
321 Invalid file format (version 97)
322 Can’t create necessary temporary file (version 97)
323 Can’t load module; invalid format (versions 5.0 and 7.0)
325 Invalid format in resource file (version 97)
327 Data value named was not found (version 97)
328 Illegal parameter; can’t write arrays (version 97)
335 Could not access system registry (version 97)
336 ActiveX component not correctly registered (version 97)
337 ActiveX component not found (version 97)
338 ActiveX component did not correctly run (version 97)
360 Object already loaded (version 97)
361 Can’t load or unload this object (version 97)
363 Specified ActiveX control not found (version 97)
364 Object was unloaded (version 97)
365 Unable to unload within this context (version 97)
368 The specified file is out of date. This program requires
a newer version (version 97)
371 The specified object can’t be used as an owner form for
Show (version 97)
380 Invalid property value (version 97)
381 Invalid property-array index (version 97)
382 Property Set can’t be executed at run time (version 97)
383 Property Set can’t be used with a read-only property
(version 97)
385 Need property-array index (version 97)
387 Property Set not permitted (version 97)
393 Property Get can’t be executed at run time (version 97)
394 Property Get can’t be executed on write-only property
(version 97)
400 Form already displayed; can’t show modally (version 97)
402 Code must close topmost modal form first (version 97)
419 Permission to use object denied (version 97)
422 Property not found (version 97)
423 Property or method not found
424 Object required
425 Invalid object use (version 97)
429 ActiveX component can’t create object or return
reference to this object (version 97)
430 Class doesn’t support OLE Automation
430 Class doesn’t support Automation (version 97)
432 File name or class name not found during Automation
operation (version 97)

438 Object doesn’t support this property or method
440 OLE Automation error
440 Automation error (version 97)
442 Connection to type library or object library for remote
process has been lost (version 97)
443 Automation object doesn’t have a default value
(version 97)
445 Object doesn’t support this action
446 Object doesn’t support named arguments
447 Object doesn’t support current locale settings
448 Named argument not found
449 Argument not optional
449 Argument not optional or invalid property assignment
(version 97)
450 Wrong number of arguments
450 Wrong number of arguments or invalid property assignment
(version 97)
451 Object not a collection
452 Invalid ordinal
453 Specified DLL function not found
454 Code resource not found
455 Code resource lock error
457 This key is already associated with an element of this
collection (version 97)
458 Variable uses a type not supported in Visual Basic
(version 97)
459 This component doesn’t support events (version 97)
460 Invalid clipboard format (version 97)
461 Specified format doesn’t match format of data
(version 97)
480 Can’t create AutoRedraw image (version 97)
481 Invalid picture (version 97)
482 Printer error (version 97)
483 Printer driver does not support specified property
(version 97)
484 Problem getting printer information from the system.
Make sure the printer is set up correctly (version 97)
485 Invalid picture type (version 97)
486 Can’t print form image to this type of printer
(version 97)
735 Can’t save file to Temp directory (version 97)
744 Search text not found (version 97)
746 Replacements too long (version 97)
1000 Classname does not have propertyname property
(versions 5.0 and 7.0)
1001 Classname does not have methodname method
(versions 5.0 and 7.0)
1002 Missing required argument argumentname
(versions 5.0 and 7.0)
1003 Invalid number of arguments (versions 5.0 and 7.0)
1004 Methodname method of classname class failed
(versions 5.0 and 7.0)
1005 Unable to set the propertyname property of the classname
class (versions 5.0 and 7.0)
1006 Unable to get the propertyname property of the classname

class (versions 5.0 and 7.0)
31001 Out of memory (version 97)
31004 No object (version 97)
31018 Class is not set (version 97)
31027 Unable to activate object (version 97)
31032 Unable to create embedded object (version 97)
31036 Error saving to file (version 97)
31037 Error loading from file (version 97)

Leave a Reply

Your email address will not be published. Required fields are marked *