Microsoft KB Archive/124160

= ACC: "Invalid Use of Null" with SysCmd Function =

Article ID: 124160

Article Last Modified on 5/6/2003

-

APPLIES TO


 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition

-



This article was previously published under Q124160



Moderate: Requires basic macro, coding, and interoperability skills.



SYMPTOMS
When you use the SysCmd function in Access Basic code, you may receive the error message "Invalid use of Null."



CAUSE
This error message occurs when the SysCmd function returns a null value and the return variable is declared as any data type other than Variant.



RESOLUTION
Make sure that the return variable for each call to the SysCmd function has a Variant data type.



STATUS
This behavior no longer occurs in Microsoft Access version 7.0.



MORE INFORMATION
The only Access Basic data type that can hold a null value is the Variant data type. Since the SysCmd function frequently returns a null value, the return variable should have the Variant data type, as in the following example:

  Dim ReturnVal As Variant ReturnVal = SysCmd(4, "Status Bar Text Message")

NOTE: In Microsoft Access version 2.0, you can replace the "4" in the above example with "SYSCMD_SETSTATUS" (a new constant in version 2.0).

If you do not explicitly declare the return variable's data type, it is implicitly declared as a Variant data type, so the following example works as well:

  Dim ReturnVal ReturnVal = SysCmd(4, "Status Bar Text Message")

Steps to Reproduce Behavior
 Start Microsoft Access and open any database.  Create a new module and enter the following line in the module's Declarations section:

     Option Explicit   Enter the following code in the module:

Sub SysCmdDemo1 Dim ReturnVal As Integer ReturnVal = SysCmd(4, "SysCmd Fails") End Sub </li> From the View menu, choose Immediate Window.</li> Type the following line in the Immediate window and then press ENTER:

SysCmdDemo1

You receive the error message stated above.</li></ol>

<div class="references_section">