Results 1 to 10 of 10
  1. #1
    bradp1979 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Location
    San Francisco, CA
    Posts
    234

    Adding if statement

    I think I may have asked this, but I don't remember if I did, and if I did, whether I did so correctly. So here we go again:

    Below is qrySERS. For events where the EntityName is an individual insteady of a company, it just comes back blank. So I need to add a statement to the highlighted cell that basically says "use EntityName. if is null EntityName, then use ClientName".



    I just don't know the proper wording.

    Thanks!

    Click image for larger version. 

Name:	qrySERS.png 
Views:	15 
Size:	34.8 KB 
ID:	23112

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    You could try this:

    ThingName: IIF(IsNull(EntityName),ClientName,EntityName)

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    If using IsNull, might as well use Nz:

    Nz(EntityName, ClientName)

    http://allenbrowne.com/QueryPerfIssue.html
    Last edited by June7; 12-28-2015 at 04:28 PM.
    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
    InsuranceGuy is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2015
    Location
    Colorado
    Posts
    126
    Both solutions will work, but both call VBA. As our Dear Allen Brown points out, you're better off using JET comparisons for speed.

    Code:
    =IIF(EntityName is null, ClientName, EntityName)
    Cheers,

    Jeff

  5. #5
    bradp1979 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Location
    San Francisco, CA
    Posts
    234
    Oddly enough, it's still not working. I tried both suggestions above by June and orange. Can I put the if statement directly in the text box, or does it have to be in the query?

  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,929
    Certainly can.

    What does 'not working' mean - error, wrong results, nothing happens?

    If you want to provide db ...
    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
    bradp1979 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Location
    San Francisco, CA
    Posts
    234
    Still not working. Here's the form in both print preview and design view, and the query. Also, I included the form the query is drawing from. Name is "EntityName", and Contact is "ClientName". I don't understand why it's not working.

    Special Events Report Sheet:
    Click image for larger version. 

Name:	SERS top.png 
Views:	6 
Size:	14.4 KB 
ID:	23199

    Special Events Report Sheet design view:
    Click image for larger version. 

Name:	SERS design.png 
Views:	6 
Size:	25.0 KB 
ID:	23200

    qrySERS:
    Click image for larger version. 

Name:	qrySERS.png 
Views:	6 
Size:	23.4 KB 
ID:	23202

    Special Event Form:
    Click image for larger version. 

Name:	Event form.png 
Views:	6 
Size:	23.5 KB 
ID:	23203

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You have the field alias set to the same name of the field.
    Maybe Access is confused. Try changing the alias to something else:

    Code:
    sEntityName: NZ(EntityName, ClientName)
    Add another column just for a check:
    Code:
    EName:IIF(EntityName is null, ClientName, EntityName)

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    However, the expression in textbox should be working, assuming the referenced fields are in the query.
    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.

  10. #10
    bradp1979 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Location
    San Francisco, CA
    Posts
    234
    Ok. Works now. I put "=IIF(IsNull([EntityName]),[ClientName],[EntityName])" in the textbox, and it's all good.

    Thank you!

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

Similar Threads

  1. Adding a Count function to current select statement
    By johnson8809 in forum Queries
    Replies: 2
    Last Post: 02-21-2015, 07:32 PM
  2. Replies: 2
    Last Post: 05-08-2014, 06:20 AM
  3. Replies: 1
    Last Post: 08-06-2013, 07:52 PM
  4. Replies: 10
    Last Post: 08-25-2012, 03:25 PM
  5. Replies: 9
    Last Post: 01-03-2012, 11:35 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