Knowledge Base |

# 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

1. Start Microsoft Access and open any database.
2. Create a new module and enter the following line in the module's Declarations section:

             Option Explicit

3. Enter the following code in the module:

             Sub SysCmdDemo1 ()
                Dim ReturnVal As Integer
                ReturnVal = SysCmd(4, "SysCmd Fails")
             End Sub

4. From the View menu, choose Immediate Window.
5. Type the following line in the Immediate window and then press ENTER:
   `SysCmdDemo1`
   You receive the error message stated above.

## REFERENCES

For more information about using the SysCmd() function in Microsoft Access version 2.0, search for "SysCmd," and then "SysCmd Function" using the Microsoft Access 2.0 Help menu.

Keywords: kberrmsg kbprb kbusage KB124160