Results 1 to 5 of 5
  1. #1
    louise is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    112

    Query syntax to fill a field if empty

    Hello,


    In a query, I would like to fill a field with the contents of another field if it is blank/null. Otherwise (i.e., if it is already filled in) leave it alone.

    So, in the query field, this task: VersionTwo: IIF(<VersionTwo is blank/null>, <Make equal to VersionOne>, <Otherwise, i.e., if it's already filled in, leave it alone>)

    And, I would need to be able to later edit VersionTwo, however it got filled in at the outset.

    I have tried a number of different syntaxes with no luck. Any help would be great!

    Thank you!

  2. #2
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,429
    there are two options

    1. blank/empty means null (not a zero length string)

    VersionTwo: nz(VersionTwo,VersionOne)

    2. blank/empty means null or a zero length string

    VersionTwo: IIF(nz(VersionTwo,"")="",VersionOne, Version2)

  3. #3
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,429
    Code:
    And, I would need to be able to later edit VersionTwo, however it got filled in at the outset.
    the code provided in the previous post is a calculated value so is not editable. Also just noticed you cannot have it call itself so you would need something like

    LatestVersion: nz(VersionTwo,VersionOne)

  4. #4
    louise is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    112
    How would this work since VersionTwo is an empty field until this expression is effected?
    Is there a way to have the field filled, and then not be a calculated field unless it is empty?

  5. #5
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,429
    I'm just going by what you said here

    So, in the query field, this task: VersionTwo: IIF(<VersionTwo is blank/null>, <Make equal to VersionOne>, <Otherwise, i.e., if it's already filled in, leave it alone>)
    A column in a query can either be a field from a table/other query or it is calculated, it can't be both

    Perhaps try explaining again what you are trying to do, use some example data and from that example data, show the outcome you require

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

Similar Threads

  1. Replies: 5
    Last Post: 01-13-2015, 11:57 AM
  2. Replies: 12
    Last Post: 10-22-2014, 02:11 PM
  3. Replies: 7
    Last Post: 08-28-2014, 01:33 PM
  4. Replies: 1
    Last Post: 04-15-2014, 02:45 PM
  5. Query Field Fill-In Automation
    By dmaach in forum Queries
    Replies: 1
    Last Post: 07-30-2010, 09:21 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