Results 1 to 5 of 5
  1. #1
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496

    deleting records with null values

    if rather than deleting the full record, the end user merely wipes out the entry, I'd like to delete the record with code (if that's what they really wanted to do)

    as an example, the table has (4) records and the user clears one;
    i then run the following code in the AfterUpdate() event
    however, the results are:
    tl count 4
    isNull 0
    not isNull 4
    after deletion, tl count 4

    effectively: nothing happens: it does not see any null records, none are deleted

    I'm stuck and any suggestions/directions will be greatly appreciated in advance,
    m.




    Code:
    If gsMsgResponse = vbYes Then
                
                    DoCmd.SetWarnings False
                    Debug.Print "tl count: " & DCount("[Prgrm_ID]", "tbeIncentive_Prgrms")
                    Debug.Print "isnull: " & DCount("[Prgrm_ID]", "tbeIncentive_Prgrms", "IsNull([Prgrm_Descript])")
                    Debug.Print "not isnull: " & DCount("[Prgrm_ID]", "tbeIncentive_Prgrms", "Not IsNull([Prgrm_Descript])")
                    
                    gsSQL = "Delete * from tbeIncentive_Prgrms" & _
                        " WHERE isnull([Prgrm_Descript]);"
                    CurrentDb.Execute gsSQL, dbFailOnError
    
                    Debug.Print "after deletion, tl count: " & DCount("[Prgrm_ID]", "tbeIncentive_Prgrms", IsNull([Prgrm_Descript]))
                
                
                Else
                    Me.cboPrg.Undo
                End If
    
                '....

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Can you try it like this:
    Code:
    DoCmd.SetWarnings False
    Debug.Print "tl count: " & DCount("[Prgrm_ID]", "tbeIncentive_Prgrms")
    Debug.Print "isnull: " & DCount("*", "tbeIncentive_Prgrms", "[Prgrm_Descript] Is Null")
    Debug.Print "not isnull: " & DCount("*", "tbeIncentive_Prgrms", "[Prgrm_Descript] Is Not Null")
                    
    gsSQL = "Delete * from tbeIncentive_Prgrms" & _
    		" WHERE [Prgrm_Descript] Is Null;"
    CurrentDb.Execute gsSQL, dbFailOnError
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    wow... that simple (?!) thnx

    ... Is Null vs. IsNull()

    for anyone else with a lesson to be learned... this article is pretty decent:
    https://www.techrepublic.com/article...ull-in-access/

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    the results are:
    tl count 4
    isNull 0
    not isNull 4
    after deletion, tl count 4
    your result shows you don’t have a record with a null value

    you can use the isnull function or is null sql, neither will delete anything since there isn’t a null value to be identified.

    it may be your value is text and what you actually have is a zls (zero length string) so you need another method which I suggest would be

    where nz([Prgrm_Descript],””)=“”



    I

  5. #5
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    the end user merely wipes out the entry,
    Has the record been saved before the code is run?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. Replies: 5
    Last Post: 09-24-2021, 10:28 AM
  2. Replies: 5
    Last Post: 03-11-2019, 02:35 PM
  3. Replies: 5
    Last Post: 08-31-2016, 06:04 PM
  4. Replies: 6
    Last Post: 02-23-2014, 03:54 PM
  5. Show null values in records
    By Nola-Edu in forum Queries
    Replies: 1
    Last Post: 04-10-2013, 12:36 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