Results 1 to 12 of 12
  1. #1
    webisti is offline The Wisher
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    115

    isnull and not isnull

    Hi
    I am trying to make a vba code to handle an update query:

    vba should look like: If sampling is not null and flagged is null then update comment with text " Buy"

    where the fields are named:


    sampling
    comment
    flagged

    how to do that (I am sure is smth easy, but my brain has a black out)

    thanks for your help

    Webisti

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,743
    IS NULL , NOT IS NULL is SQL related

    IsNull() and Not IsNull() are vba functions

    see this for more info

  3. #3
    webisti is offline The Wisher
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    115
    I meant IsNull() and Not IsNull()

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,743
    Did you look at the link I gave you?

  5. #5
    webisti is offline The Wisher
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    115
    Yes I did but is not solving my issue
    because instead of updating only where both conditions are met , the code is updating all records on the comment field.
    my code is RunSQL: UPDATE orders SET order.COMMENT = ' OK TO BUY ' WHERE ISNULL(sampling) and ISNULL(flagged) ;

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,965
    Saving calculated data (data dependent on other data) is usually a bad idea. This status can be calculated whenever needed with expression in query or textbox.

    However, try:

    CurrentDb.Execute "UPDATE orders SET COMMENT = 'OK TO BUY' WHERE sampling Is Null And flagged Is Null;"
    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.

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,743
    As I said earlier and June7 mentions IsNull is a vba function; Is NULL is sql.

    Are you sure the fields are NULL (unknown or undefined).

    Could the fields be blanks or zero length strings????

    Before doing an UPDATE, you should verify your logic by doing a SELECT (which is read only) and ensure the fields and values involved.

  8. #8
    webisti is offline The Wisher
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    115
    Hi
    The fields are blank...empty. nothing there.
    I will try to modify the code as you said and will let you know once done.

    thanks

    webisti

  9. #9
    webisti is offline The Wisher
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    115
    I TRIED THIS CODE BUT IS REPLACING ALL records on the comment field:
    Private Sub update_Click()
    CurrentDb.Execute "UPDATE orders SET orders.COMMENT = '' WHERE NOT ISNULL(sampling) AND ISNULL(FLAGED_BY) ;"
    End Sub
    instead of just updating those 5 records where the sampling is not blank (flagged_by is blank), it is updating everything....
    any ideas

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,743
    Did You try the code that June7 suggested?

    CurrentDb.Execute "UPDATE orders SET COMMENT = 'OK TO BUY' WHERE sampling Is Null And flagged Is Null;"

  11. #11
    webisti is offline The Wisher
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    115
    Yes I did, but nothing....same result as before..

  12. #12
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,743
    Code:
    Select Comment
    , iif(IsNull(sampling),"S_Is_Null", "S_Not_NULL, Flagged_Is(" & Flagged &")"
    , iif(IsNull(flagged,"F_is_Null", "F_Not_NULL, Sampling_Is(" & Sampling &")"
    FROM
    Orders;
    Try running this. copy it and paste it in the SQL view of the query wizard.

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

Similar Threads

  1. IIF IsNull
    By angie in forum Forms
    Replies: 11
    Last Post: 12-17-2013, 02:25 PM
  2. Using Between with iif isnull
    By TonyB in forum Queries
    Replies: 5
    Last Post: 09-03-2013, 09:56 AM
  3. If IsNull Value, Then need to be Zero
    By burrina in forum Forms
    Replies: 2
    Last Post: 11-18-2012, 02:53 AM
  4. IsNull
    By JJCHCK in forum Programming
    Replies: 3
    Last Post: 09-09-2011, 07:57 AM
  5. dcount and isnull
    By Madmax in forum Access
    Replies: 7
    Last Post: 06-22-2011, 09:31 AM

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