Results 1 to 6 of 6
  1. #1
    woodybware is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    3

    IIF-then statement to calculate data from one of two fields

    I currently am using the following coding to calculate a score based upon the GPA that is found in the form field txtBSNCummulativeGPA.

    =IIf([txtBSNCummulativeGPA]>=4,3,IIf([txtBSNCummulativeGPA]>=3.9,2.8,IIf([txtBSNCummulativeGPA]>=3.8,2.6,IIf([txtBSNCummulativeGPA]>=3.7,2.4,IIf([txtBSNCummulativeGPA]>=3.6,2.2,IIf([txtBSNCummulativeGPA]>=3.5,2,IIf([txtBSNCummulativeGPA]>=3.4,1.8,IIf([txtBSNCummulativeGPA]>=3.3,1.6,IIf([txtBSNCummulativeGPA]>=3.2,1.4,IIf([txtBSNCummulativeGPA]>=3.1,1.2,IIf([txtBSNCummulativeGPA]>=3,1.0)))))))))))

    In some cases, the txtBSNCummulativeGPA field might be blank, and in such cases I would like the function to then apply the value in the txtOtherBSNGPA field on this form to the calculation above. So essentially if txtBSNCummulativeGPA is null, then factor txtOtherBSNGPA. If the txtBSNCummulativeGPA has a value, that should be the default.



    Thanx!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Try Nz function: Nz([txtBSNCummulativeGPA], [txtOtherBSNGPA])

    However, this expression is getting rather long and might exceed limit. Long names chew up that limit.

    Choose and Switch functions can often serve instead of nested IIf but will still be a long expression.

    Consider a textbox named txtGPA on form/report with expression: =Nz([txtBSNCummulativeGPA], [txtOtherBSNGPA])

    Then use that textbox in the conditional expression:

    =Switch([txtGPA]>=4,3, [txtGPA]>=3.9,2.8, [txtGPA]>=3.8,2.6, [txtGPA]>=3.7,2.4, [txtGPA]>=3.6,2.2, [txtGPA]>=3.5,2, [txtGPA]>=3.4,1.8, [txtGPA]>=3.3,1.6, [txtGPA]>=3.2,1.4, [txtGPA]>=3.1,1.2, [txtGPA]>=3,1)
    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.

  3. #3
    woodybware is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    3
    I like the option you proposed and can just use the txtGPA as a hidden field. In my case though, txtOtherBSNGPA will often be null. How do I pull up the form without it requesting data for txtOtherBSNGPA or txtBSNCummulativeGPA using the example you provided when one field is null?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Don't understand, why would there be a request for data? Are txtOtherBSNGPA and txtBSNCummulativeGPA the names of fields or textboxes? Will one or other always have a value?
    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.

  5. #5
    woodybware is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    3
    Sorry, let me clarify, the document I am working on is actually a report that is pulling the data for txtOtherBSNGPA and txtBSNCummulativeGPA from a Form called MSNEvaluation. When I generate the report using the coding you provided, the report requests a value for txtOtherBSNGPA when it is null.

    The control source for txtBSNCummulativeGPA is =Forms!frmMSNEvaluation!txtBSNCumGPA
    The control source for txtOtherBSNGPA is =[Forms]![frmMSNEvaluation]![txtOther_Bachelors_Cum_GPA]

    Might it be easier to create a non-visible field txtGPA like you suggested and have the control source reference back to the forms? So txtGPA would equal txtBSNCumGPA, but if txtBSNCumGPA was null, would equal txtOther_Bachelors_Cum_GPA. What would the control source code look like for txtGPA in this scenario?

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    I don't understand why report would request a value if [Forms]![frmMSNEvaluation]![txtOther_Bachelors_Cum_GPA] is null. Whether that form control is Null, a number, text, or empty string, the report control should just reflect that. The expression in txtGPA references report controls, not fields, so setting the txtGPA textbox to an expression that references the two form controls will probably not resolve this.

    Why are these GPA values pulled from a form and are not data in the report RecordSource?

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

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

Similar Threads

  1. Replies: 2
    Last Post: 02-11-2013, 01:26 PM
  2. Replies: 5
    Last Post: 02-11-2013, 08:34 AM
  3. Replies: 34
    Last Post: 12-01-2011, 08:18 AM
  4. Replies: 1
    Last Post: 12-12-2010, 05:03 PM
  5. Calculate Multiple Fields for Extended Price
    By SRessler in forum Queries
    Replies: 3
    Last Post: 11-01-2010, 03:57 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