This error occurs in Microsoft Office applications when in the vba code a variable has no value and should be transferred to another location.


In this example, if the variable varSTring was never used and therefore has the value zero, then it can not be applied to test.

Test= varString


When you take values from a database or recordset, it is common.

lblHead_Bauvorhaben.Caption = recHeader("Bauvorhaben")



You have to enclose the emergency-zero function with the transfer. This function nz (variable, new_value) states that if the variable is zero then another default value should be adopted.

This means in the example the function nz (variable, "") transfers a space if there is no value.

lblHead_Bauvorhaben.Caption = Nz(recHeader("Bauvorhaben"), "")


In vba code page

Error Code 94: Invalid Use of Null


Example of the correction when data is taken from a recordset by Access

Private Sub fl_Load_Header()

    '--------------------< fl_Load_Header() >--------------------

    Dim ID_Projekt As Long

    ID_Projekt = Form_frm_Projekte.ctlListe



    Dim recHeader As Recordset

    Set recHeader = CurrentDb.OpenRecordset("SELECT * FROM tbl_Projekte WHERE ID_Projekt=" & Form_frm_Projekte.ctlListe, dbOpenSnapshot)

    If Not recHeader.EOF Then

        lblHead_ID_Projekt.Caption = ID_Projekt

        lblHead_Bauvorhaben.Caption = Nz(recHeader("Bauvorhaben"), "")

        lblHead_Kunde.Caption = recHeader("Kunde_Firmenname")

        lblHead_Datum_Projekt.Caption = Nz(recHeader("Datum_Projekt"), "")

    End If



    '--------------------</ fl_Load_Header() >--------------------

End Sub


Software Entwicklung Stuttgart NĂ¼rtingen
Suche Projekte C#, WPF, Windows App,ASP.Net, vb.Net, WinForms, SQL Server, Access, Excel