+ Reply to Thread
Results 1 to 4 of 4

Run-time error 94; Invalid use of Null

  1. #1
    Registered User
    Join Date
    08-21-2012
    Location
    Crewe, England
    MS-Off Ver
    Excel 2007
    Posts
    37

    Run-time error 94; Invalid use of Null

    Hello Excel Forum,
    I'm running a macro that retrieves data from database and sorts it based on a field, which contains a date value. If the value of the field is less than the current date or doesn't contain anything (i.e. is null), I want to do something with it. The code is as follows:

    Please Login or Register  to view this content.
    However, when the code reaches this line I get 'invalid use of null'. I've tested the value of the field in the Immediate window and the field value on the very first data line is Null. How can I achieve what I'm trying to do?

    Thanks

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Run-time error 94; Invalid use of Null

    I reckon you'll need two separate tests since an Or conditions will test both and you can't use datevalue with null
    Please Login or Register  to view this content.
    or change your query so that it returns something other than null
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Run-time error 94; Invalid use of Null

    You need to separate the 2 criteria as you can't use DateValue with Null, which is why you get the error.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    08-21-2012
    Location
    Crewe, England
    MS-Off Ver
    Excel 2007
    Posts
    37

    Re: Run-time error 94; Invalid use of Null

    Thanks JP and Norie. I've split the conditions and it's working as intended.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1