Microsoft KB Archive/221343

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

Article ID: 221343

Article Last Modified on 12/12/2002

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



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.  Open the Suppliers form in Design view. View the OnCurrent property setting of the form, and note that it has [Event Procedure].  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])   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                    Compile the code, close the Visual Basic Editor, and view the Suppliers form in Form view. Add a new record and note that the error message no longer occurs.</li></ol>

<div class="status_section">

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

<div class="moreinformation_section">

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.

<div class="references_section">