Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2004
    Posts
    7

    Question Unanswered: Invalid Use Of Null (driving me mad!!)

    Ok, I've got a label that I want to display the value of a particular field as I change records, this works fine untill I reach the end of the records and there is obviously no value to put into the label so I get an "invalid Use Of Null" error message.

    Heres my code:

    If IsNull(owner_name.Value) Then
    Label7.Caption = ""
    ElseIf Not IsNull(owner_name.Value) Then
    Label7.Caption = owner_name.Value
    End If

    have also tried:

    If IsNull(owner_name) Then
    Label7.Caption = "-"
    Else
    Label7.Caption = owner_name.Value
    End If

    Can some one please help!

  2. #2
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    I have always used:

    If owner_name.Value & ""="" Then

    I treats null and empty string as the same thing.

    Are you sure that you are getting the error on one of these lines? Typically 'Invalid use of null' appears when you are passing a null to a function that is expecting a specific type. IsNull expects a null value and should not be giving you the error.

    What line is yellow when you debug the code?

  3. #3
    Join Date
    Oct 2004
    Posts
    7
    Im trying to pass the value found in owner_name to the caption of label7

    when the value in the owner_name field is "mike" the label says "mike", and so on untill the next record button takes the database to the end and the field is Null and therefore there is no value in Owner_name to pass to the label.

  4. #4
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    Try this:

    Code:
    If owner_name.Value & ""="" Then
    Label7.Caption = ""
    Else
    Label7.Caption = owner_name.Value
    End If

  5. #5
    Join Date
    Oct 2004
    Posts
    7
    Nope sorry, thats still giving me the error message. not going to debug mode tho, just showing the message with 'ok' button. I could change the forms recordset typr to 'snap shot' so I don't get an empty record while I cycle but this would still give me a problem when the database was empty i.e its first use!

  6. #6
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    I think the problem is somewhere else. The IsNull function should not give you that error message. And if you are not able to debug it then I would imagine it is in a query or SQL statement.

  7. #7
    Join Date
    Oct 2004
    Posts
    7
    it must be that code because when I remove it, it all works fine! maybe theres another way, can I somehow identify that the field is null and then not run the (Label7.Caption = Owner_Name.Value) code?

Posting Permissions

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