Problem with IIf

Posted on 2011-10-21
Last Modified: 2013-11-05
I am having a problem with an IIf in a text box control source.  What is wrong with this code?

=IIf([txtTotal PartNQtyNeeded]-[txtTotAvail])=<0, 0, [txtTotal PartNQtyNeeded]-[txtTotAvail])

Question by:SteveL13
    LVL 119

    Accepted Solution

    the "=" sign must be after the "<"

    =IIf([txtTotal PartNQtyNeeded]-[txtTotAvail])<= 0, 0, [txtTotal PartNQtyNeeded]-[txtTotAvail])

    Author Comment

    Got that.  But I also get an error...  "The espression you entered has a function containing the wrong number of arguments".

    LVL 119

    Expert Comment

    by:Rey Obrero
    check again what you have ...

    Author Comment

    Here is exactly what I have... (copy and paste)

    LVL 61

    Assisted Solution

    In addition to what cap noticed, your parentheses were mismatched.

    You can do either this:
    = IIf(([txtTotal PartNQtyNeeded]-[txtTotAvail]) <= 0, 0, [txtTotal PartNQtyNeeded]-[txtTotAvail])

    Or this:

    =IIf([txtTotal PartNQtyNeeded]-[txtTotAvail] <= 0, 0, [txtTotal PartNQtyNeeded]-[txtTotAvail])

    LVL 61

    Expert Comment

    Just a tip...

    For syntactical issues in control sources like this, you can put the expression in the VBA editor like this:

    x = IIf([txtTotal PartNQtyNeeded]-[txtTotAvail] <= 0, 0, [txtTotal PartNQtyNeeded]-[txtTotAvail])

    Doing so makes it easier to track down errors (the expressions turn red if the syntax is off).

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Suggested Solutions

    It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
    I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now