Results 1 to 4 of 4
  1. #1
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93

    CDate and CStr issue with "Invalid Use of Null" Issue

    Hello Accessers,



    I am experiencing an 'Invalid Use of Null' issue with this expression:
    Code:
    Anniversary Date: CDate(CStr(DatePart("m",[initialaccreddate]))+"/"+CStr(DatePart("d",[initialaccreddate]))+"/"+CStr(DatePart("yyyy",Now())))
    On one database it works. But when I copy the same on another database and then the same expression does not work. It shows "Invalid use of Null" error.

    The field initialaccreddate is the same on both databases.

    What is the culprit of the issue?!

    Your help will be thanked and a star will be given for your reputation!

    -ME

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I would check the data in your initialaccreddate field in the database where you are getting the error. Do you have any Null values in the is field?
    If so, it is causing errors for your function (i.e. you cannot pull a "month" or "date" component out of a date that does not exist).

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    All of the conversion functions (CStr, CDate, CInt, etc) error with Null. If the field is Null, the expression errors. Does every record have data?

    Number conversion functions will trigger a type mismatch error on empty string.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93
    Answer: For all of the conversion functions (CStr, CDate, CInt, etc.), make sure there are no null values in the field in the table it is deriving the data from. Simple rule and easy to remember.

    Thanks JoeM and June7!

    Marking as SOLVED.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 11-13-2013, 08:56 AM
  2. Replies: 7
    Last Post: 02-23-2012, 07:19 PM
  3. Replies: 3
    Last Post: 12-20-2011, 08:41 AM
  4. StrComp causing "Invalid use of Null" error
    By sephiroth2906 in forum Programming
    Replies: 5
    Last Post: 09-15-2011, 07:06 PM
  5. Update query from form "invalid use of null"
    By Lady_Jane in forum Programming
    Replies: 4
    Last Post: 08-16-2011, 01:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums