Troubleshoot Visual Basic code

Microsoft Office Access 2003

You can temporarily stop the display of warnings and other messages while Microsoft Visual Basic code is running by using the SetWarnings method to carry out the SetWarnings action. You can also use the SetWarnings method to restart the display of messages.

ShowMy procedure produces unexpected results when I use one of the Find methods.

The FindFirst, FindLast, FindNext, and FindPrevious methods might produce unexpected results for the following reasons:

  • The criteria argument you specified uses invalid syntax to refer to the value of a control or property.
  • The criteria argument you specified uses invalid syntax to combine the value of a field, control, or property with a literal string.

The FindRecord and FindNext methods might produce unexpected results if the FindRecord method's onlycurrentfield argument is set to acCurrent. Use the GoToControl method to move the focus to the control containing the data you're searching for before using the FindRecord or FindNext method.

ShowI get a "Sub or Function not defined" message when I try to use the IsLoaded function.

The IsLoaded function is a sample Function procedure included with the Northwind sample database, and not a built-in Microsoft Visual Basic function. To use the IsLoaded function in your database, you must copy it to your database.

  1. Open the Northwind sample database.

    ShowHow?

    1. On the Help menu, point to Sample Databases, and then click the database you want to open.
    2. If the database isn't currently installed, click Yes to install it now.

    Note   If you don't see a list of databases when you point to Sample Databases, you can install them by double-clicking Add/Remove Programs in Windows Control Panel and running Office Setup.

  2. In the Database window of Northwind, click Modules Button image under Objects.

  3. Select Utility Functions, and then click the Design on the Database window toolbar.

  4. Highlight and copy the function.

  5. Close the Northwind sample database.

  6. In the Database window of your database, click Modules Button image under Objects and then click New on the Database window toolbar.

  7. Paste the code into the module.

  8. Close and save the new module.

ShowI get a "Method or data member not found" message when I try to refer to a table field in code.

Microsoft Access displays this message if you use the . (dot) operator rather than the ! operator to refer directly to a table field. For example, this error is produced by the last line of the following block of Microsoft Visual Basic code:

Dim dbsCurrent As Database
Dim tblTest As TableDef
Dim fldTest As Field

Set dbsCurrent = CurrentDb
Set tblTest = dbsCurrent.TableDefs("Categories")
Set fldTest = tblTest.CategoryID
				

To correct the problem, replace the . (dot) operator with the ! operator or refer to the field as an element of the Fields collection. You can use either of the following lines of code, although the first might result in faster performance:

Set fldTest = tblTest!CategoryID

Set fldTest = tblTest.Fields("CategoryID")