dcsimg
Results 1 to 7 of 7

Thread: [RESOLVED] runtime error '94' Invalid use of Null when i view my report??

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    108

    Resolved [RESOLVED] runtime error '94' Invalid use of Null when i view my report??

    Hi,
    When i view my report got this error, runtime error '94' invalid use of null, but my database all have data?? if i use 'on error resume next' will blank report. Anyone can help me to re-solve this problem,Thank you.

    your help is much appreciated.

    Code:
    Public Sub SumSH()
    RS1Check
    rs1.Open "Select sum(sh) From Daily where dt between #" & DTPicker2 & "# and #" & DTPicker3 & "#", cn, adOpenDynamic, adLockPessimistic
    Text1.Text = rs1.Fields(0) 'THIS LINE CAUSE THE ERROR
    End Sub
    
    Private Sub ViewReport_Click()
    On Error GoTo 0
    
    If MsgBox("          View Report?", vbYesNo, "View Report") = vbYes Then
    DataReport1.Orientation = rptOrientLandscape
    End If
    
    DataEnvironment1.Commands(1).CommandText = "Select * From Daily Where Dt Between #" & DTPicker2 & "# and #" & DTPicker3 & "# Order by Dt"
    DataReport1.Show
    
    SumSH
    
    Load DataEnvironment1
    With DataEnvironment1
    If .rsCommand1.State <> 0 Then .rsCommand1.Close
    .Command1
    End With

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,135

    Re: runtime error '94' Invalid use of Null when i view my report??

    YOu can use IsNull() function to check if value is null:
    Code:
    If Not IsNull(rs1.Fields(0)) Then
        Text1.Text = rs1.Fields(0)
    End If
    OR

    Text1.Text = "" & rs1.Fields(0)

    will also work.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    108

    Re: runtime error '94' Invalid use of Null when i view my report??

    thank you for your quick reply, no more error msg already, but still got blank report??

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,144

    Re: runtime error '94' Invalid use of Null when i view my report??

    That is because the value being returned by the recordset is still Null, you haven't changed that - all you have done is stop the error occurring (which is a good thing).

    The most likely reason for the value being Null is due to no records in your database matching your Where clause, which is easily possible as you can't actually tell what the Where clause is (you can only see the code that creates it, and can't tell what formatting etc is being used for the values).

    I recommend reading two of the articles from our Database Development FAQs/Tutorials (at the top of the Database Development forum), as they are very likely to help with solving it:

  5. #5
    Addicted Member
    Join Date
    Oct 2008
    Location
    India, Kerala, Calicut
    Posts
    242

    Re: runtime error '94' Invalid use of Null when i view my report??

    try this..its because of null values

    Code:
    Text1.Text = iif(isnull(rs1.Fields(0)),"",rs1.Fields(0))

  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,135

    Re: runtime error '94' Invalid use of Null when i view my report??

    @sanju4kk:

    The IIf function evaluates every expression and if one of them returns error then that's what function will return.
    In OP's case because rs1.Fields(0) contains Null the "Invalid use of Null" error will be returned.
    To see how it actually works try this:
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Dim a As Integer, b As Integer
    
        a = 1
        b = 0
        Debug.Print IIf(a / b = 0, "zero", a / b)
    
    End Sub
    Example above should return run time error "Division by Zero" - since error is unhandled program will exit.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    108

    Re: runtime error '94' Invalid use of Null when i view my report??

    re-solved already,the problem is the date formatted incorrect. thank you all of you guy ,especially si_the_geek your info help me solved this problem..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width