none
Invalid use of Null- Error 94 RRS feed

  • Question

  • I wrote this code in one of my forms but I don't know why when I update a combobox in subform I got an error that says:" Invalid use of Null". I checked the code several time but I don't know how can I prevent or solve it.
    Private Sub Form_BeforeUpdate(Cancel As Integer)
        'For avoiding two value in QtyAdded and QtyDeducted I added this code
        
        If Me.QtyAdded.Value <> 0 And Me.QtyDeducted <> 0 Then
            MsgBox "ÝÞØ í˜í ÇÒ ÝíáÏåÇí æÇÑÏå íÇ ÕÇÏÑå ãíÊæÇääÏ ãÞÏÇÑ ÏÇÔÊå ÈÇÔäÏ", vbOKOnly + vbCritical, "Duplicate Value"
            Me.QtyAdded.Value = 0
            Me.QtyDeducted.Value = 0
            Cancel = True
        End If
        
        'For controling the minus inventory I add this procedure
            Const Message = "ÈÇÇÚãÇá Çíä ÊÑǘäÔ ãæÌæÏí ãäÝí ãíÔæÏ¡áØÝÇ ËÈÊ ÑÇ ÇÕáÇÍ äãÇííÏ"
            Dim lngStockInHand As Long
            Dim strWhere As String
        'Find the criteria for comparing balance
            
        strWhere = "True"
        If Not IsNull(Me.Parent.StockID) Then
            strWhere = strWhere & " AND tblInventoryTransaction.StockID= " & Me.Parent.StockID
        End If
        If Not IsNull(Me.InventoryID) Then
            strWhere = strWhere & "AND tblInventory.InventoryID= " & Me.InventoryID
        End If
            lngStockInHand = DLookup("Balance", "qryInventoryBalanceControl", strWhere)
        If Me.QtyDeducted > lngStockInHand Then
            MsgBox Message, vbExclamation + vbMsgBoxRight + vbMsgBoxRtlReading, "ÚÏã ˜ÝÇíÊ ãæÌæÏí"
            Cancel = True
        End If
            
            
    End Sub


    Regards,

    Monday, February 22, 2016 9:31 PM

Answers

  • I wrote this code in one of my forms but I don't know why when I update a combobox in subform I got an error that says:" Invalid use of Null". I checked the code several time but I don't know how can I prevent or solve it.

    Hi kvaziri,

    Place a breakpoint (e.g. Stop) at the beginning of the sub, and step through the code with the debugger. You can then see which line gives the error. By hoovering with the cursor over a variable, you can see its current value,

    Imb.

    • Proposed as answer by David_JunFeng Thursday, March 3, 2016 7:01 AM
    • Marked as answer by David_JunFeng Thursday, March 3, 2016 7:01 AM
    Monday, February 22, 2016 9:47 PM

All replies

  • I wrote this code in one of my forms but I don't know why when I update a combobox in subform I got an error that says:" Invalid use of Null". I checked the code several time but I don't know how can I prevent or solve it.

    Hi kvaziri,

    Place a breakpoint (e.g. Stop) at the beginning of the sub, and step through the code with the debugger. You can then see which line gives the error. By hoovering with the cursor over a variable, you can see its current value,

    Imb.

    • Proposed as answer by David_JunFeng Thursday, March 3, 2016 7:01 AM
    • Marked as answer by David_JunFeng Thursday, March 3, 2016 7:01 AM
    Monday, February 22, 2016 9:47 PM
  • >>>I wrote this code in one of my forms but I don't know why when I update a combobox in subform I got an error that says:" Invalid use of Null".

    According to your description, I suggest that you could figure out which line gives the error "Invalid use of Null", otherwise you could use the Nz function to return zero, a zero-length string (" "), or another specified value when a Variant is Null. For example, you can use this function to convert a Null value to another value and prevent it from propagating through an expression.

    For more information, click here to refer about Nz Function

    Tuesday, February 23, 2016 1:57 AM