• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint


Q1:My code stops on a line of code with an error message, with a function highlighted, but I know the line of code is OK. What is the problem?
A1: Your code may use early binding of variables, using specific object types in declarations such as
Dim ctl As Control

If the line of code uses a method or property that is not appropriate for the declared object type, you will get an error. To fix this problem, inspect the available methods, properties, or arguments, and select one that belongs to the object you are using.

Or you may have used a function from another application's dialect of VBA, such as the Nz function from Access VBA. If you use early binding, you must have a reference set to the appropriate object library; otherwise, the object (Control in this case) won't be recognized. Similarly, if you use a function from another application's dialect of VBA, you must have a reference set to that object library. To check whether this may be a problem, implement the following steps:

  1. If your code has stopped with an error message, click the OK button in the dialog box, as shown in Figure 43.47.

    Figure 43.47. An error message highlighting the Nz function.

  2. Click the Reset button on the toolbar to reset the code, as shown in Figure 43.48.

    Figure 43.48. Resetting code after an error.

  3. Pull down the Tools menu and select the Reference command.

  4. Locate the appropriate object library in the list and click it. In this case, the Nz function requires the Access 9.0 object library, so Figure 43.49 shows this object library being checked.

    Figure 43.49. Setting a reference to the Access 9.0 object library.

  5. Close the References dialog box.

  6. Try running the code again; it should run now.


Sometimes the missing object library is indicated by the word "MISSING" in the list of object libraries (next to the library's name), but you can't count on this.

Q2: How can I get projects from Outlook, Access, and Word to display in the same VBE window?
A2: Unfortunately, this is not possible. Each Office application opens its own VBE window.
Q3: Will my Outlook VBA code work with Outlook 97 or 98?
A3: No; Outlook VBA only works with Outlook 2000.
Q4: My code runs without error messages, but I am not getting the results I intended. How can I find out what is wrong with the code?
A4: Try using Debug.Print statements in your code to display the values of any variables you are using. (Press Ctl+G in the VBE window to open the Immediate Window, where you see the results of these statements.)
Q5:My code runs correctly up to a certain point, but I can't figure out exactly where the problem is. Can I make the code execute more slowly, so I can see what is happening?
A5: You can step through your code a line at a time by setting a breakpoint in the code (say, just before the problem area). To set a breakpoint, click the Break button on the toolbar, or press F9. Then press F8 repeatedly, to run the code a line at a time.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint