Results 1 to 13 of 13
  1. #1
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232

    iff or nz statement

    I am using the following as the default value for a field in a form. if the owner address is not null it shows the information in the field , but if the owner address is null the following customer information listed name,address,city,state,zip does not show. should this be IFF statement and not the NZ statement...

    =Nz([Forms]![Customer]![Owner Address],[Forms]![customer]![firstname] & " " & [Forms]![customer]![lastname] & Chr(13) & Chr(10) & [Forms]![customer]![street number] & " " & [Forms]![customer]![address] & Chr(13) & Chr(10) & [Forms]![customer]![City] & " " & [Forms]![customer]![state] & " " & [Forms]![customer]![zip])


    this is what is in the control source for the owner address...
    =[CompID].COLUMN(1) & Chr(13) & Chr(10) & [CompID].COLUMN(2) & Chr(13) & Chr(10) & [CompID].COLUMN(3) & " " & [CompID].COLUMN(4) & " " & [CompID].column(5)



    Did know if you would need the above added just in case Thanks Angie

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Nz is for handling Nulls so you don't get an error. Her is a link that may be helpful. http://office.microsoft.com/en-us/ac...001228890.aspx

  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
    You say the first expression is in DefaultValue property? DefaultValue only triggers with a new record. A record is initiated with first input to any control and that will trigger the DefaultValue. Also, DefaultValue is intended to save value to record. Do you really want to save that info into record?

    Use the Nz expression in ControlSource or in 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.

  4. #4
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    Yes I do want to save it ( it's the billing address for creating a invoice for a service call)
    i am creating a new record when I create a new invoice.
    If the owners address is empty than I want to bill the customer.

  5. #5
    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
    What is this form behavior? Is this a form/subform? How are the owner and customer known to the form?

    I doubt DefaultValue will help with this requirement. Saving the full address string will probably require code (I use only VBA, not macros).
    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.

  6. #6
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    Nz Angies.zip

    I am attaching a db to try and explain. when you open it and go to customer form there is two records created. on the first record if you select "service call" button up top it will open the service calls for that customer, then select create invoice. the top box should have the billing address for the customer since no owner is selected, but nothing is showing.

    if you go to the second customer record and do the same you will see that the owner address shows in the box because the owner was selected in the customer form.

    what I want to do is if a owner is selected then that address information will show if not it will be the customer default information for billing. (in my old DB it worked fine but I am reworking a few things to clean the DB up a little and now I am having problems)

    I have tried several different things to fix the above but so far no luck . Any suggestions would help thanks Angie
    Last edited by June7; 05-11-2014 at 04:34 PM.

  7. #7
    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
    Those steps open Workorders form. The 'top box' is a combobox bound to Bill To field. I don't see any place for address display on Workorders form. How is this supposed to supply address info to Customer form?

    Seems to me you want that IIf expression in textbox on Customer form.

    Then if you want to save the full address string, will need code in some event, perhaps form BeforeUpdate. What record do you want to save the string to?
    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.

  8. #8
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    When you open the property sheet for the bill to. The default value is entered. I have the bill to as a combo box because sometime I have to bill a insurance company or warranty company that is Listed in the combo box. But the bill to is always the customer information unless there is a owner . I will try to make a bill to field in the main form customer.

  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
    I now see there are Bill To fields in Customers and Workorders tables. And also see the DefaultValue setting in the combobox. Problem is the Nz references the textbox with concatenated string. That textbox is never null nor empty string because of the concatenation with spaces and Chr(13) & Chr(10). Use IIf() expression instead and reference the CompID combobox.

    IIf(Not IsNull([Forms]![Customer]![CompID]), [Forms]![Customer]![Owner Address], ...)
    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
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    Is this how I will need to write it?

    =IIF(not isnull([forms]![customer]![compid]),[forms]![customer]![company address],[Forms]![customer]![firstname] & " " & [Forms]![customer]![lastname] & Chr(13) & Chr(10) & [Forms]![customer]![street number] & " " & [Forms]![customer]![address] & Chr(13) & Chr(10) & [Forms]![customer]![City] & " " & [Forms]![customer]![state] & " " & [Forms]![customer]![zip])

  11. #11
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    I tried the above but get error. The expression you entered contains invalid syntax

  12. #12
    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
    This works:

    IIf(Not IsNull([Forms]![Customer]![CompID]),[Forms]![Customer]![Owner Address],[Forms]![customer]![firstname] & " " & [Forms]![customer]![lastname] & Chr(13) & Chr(10) & [Forms]![customer]![street number] & " " & [Forms]![customer]![address] & Chr(13) & Chr(10) & [Forms]![customer]![City] & " " & [Forms]![customer]![state] & " " & [Forms]![customer]![zip])
    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.

  13. #13
    angie is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Dec 2013
    Posts
    232
    Thank you again June7. You are great. It worked wonderful. Thanks Angie

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

Similar Threads

  1. Using the iif statement
    By Brien in forum Access
    Replies: 4
    Last Post: 11-05-2012, 12:08 PM
  2. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  3. Replies: 7
    Last Post: 08-17-2011, 01:49 PM
  4. Need Help with SQL Statement
    By Hank44 in forum Programming
    Replies: 3
    Last Post: 11-08-2010, 05:49 PM
  5. SQL like statement?
    By Cojack in forum Queries
    Replies: 4
    Last Post: 09-21-2010, 04:45 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