ACC2000: "Invalid Use of Null" Error When You Try to Add a Record to a Form in NorthwindCS.adp (221343)



The information in this article applies to:

  • Microsoft Access 2000

This article was previously published under Q221343
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies only to a Microsoft Access project (.adp).

SYMPTOMS

When you try to assign the value of a control to some other object in a Microsoft Access project, you may receive the following error message:
Invalid use of Null

RESOLUTION

Use the IsNull function to verify the control's value before you assign the value to some other object. To see an example of how to do so, follow these steps. This example uses the Suppliers form in the sample project NorthwindCS.adp.
  1. Open the Suppliers form in Design view.
  2. View the OnCurrent property setting of the form, and note that it has [Event Procedure].
  3. Click the Build (...) button next to the OnCurrent property box to open the Private Sub Form_Current() event procedure.

    The line of code that causes the error is:
    strLinkCriteria = "SupplierID = " + CStr(Forms![Suppliers]![SupplierID])
    					
  4. Place this line of code within a conditional statements. For example:
    If Not IsNull(Forms![Suppliers]![SupplierID]) Then
       strLinkCriteria = "SupplierID = " + CStr(Forms![Suppliers]![SupplierID])
    End If
    					
  5. Compile the code, close the Visual Basic Editor, and view the Suppliers form in Form view.
  6. Add a new record and note that the error message no longer occurs.

STATUS

Microsoft has confirmed that this is a problem in Microsoft Access 2000.

MORE INFORMATION

This symptom is specific to Access 2000 projects. However this same error may occur whenever you use Visual Basic for Applications (VBA) code in Access.

It is common, for example, to use VBA code to reference controls on a form and to assign the values returned (by the reference) to some other object, such as a variable. If the control on the form contains a Null value, and the code attempts to assign this value to a String variable for example, you receive the error message described in the "Symptoms" section.

Steps to Reproduce the Behavior

  1. Open the sample database NorthwindCS.adp.
  2. Open the Suppliers form in Form view.
  3. On the Edit menu, point to Go To, and then click New Record. Note that you receive the error message mentioned in the "Symptoms" section.

REFERENCES

For more information about the IsNull function, click Microsoft Visual Basic Help on the Help menu, type IsNull in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

Modification Type:MajorLast Reviewed:12/12/2002
Keywords:AccessCS kbbug KbClientServer kbdta KB221343