Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2002
    Posts
    2

    Unanswered: Microsoft Access

    I'm trying to build an expression using the "And" and the "OR" operators but cannot get them to work. I don't know the proper syntax.

  2. #2
    Join Date
    Nov 2001
    Posts
    336
    Hi,

    Here is an example

    dim lngI as long
    dim lngJ as long
    dim bolTest as boolean

    lngI=12
    lngJ=5
    bolTest=True

    if (lngI=12 AND lngJ<>6 ) or bolTest then
    msgbox "I always see this message"
    endif

    Igor

  3. #3
    Join Date
    Dec 2001
    Posts
    7

    Sollution....

    if (lngI=12 AND lngJ<>6 ) or bolTest then

    Does not do what I think you wanted to do.
    This, is what the code does....

    if (lngI=(12 AND lngJ)<>6 ) or bolTest then

    (see the "hidden" bit-wise AND operation?)
    Change your code to this...

    if ((lngI=12) AND (lngJ<>6)) or bolTest then

    HTH.

  4. #4
    Join Date
    Jun 2002
    Posts
    2

    Re: Sollution....

    Originally posted by stein
    if (lngI=12 AND lngJ<>6 ) or bolTest then

    Does not do what I think you wanted to do.
    This, is what the code does....

    if (lngI=(12 AND lngJ)<>6 ) or bolTest then

    (see the "hidden" bit-wise AND operation?)
    Change your code to this...

    if ((lngI=12) AND (lngJ<>6)) or bolTest then

    HTH.
    Thanks for your help. I guess I didn't do a good job of explaining exactly what I'm trying to do. I have fields called "LastReport", "NCOsDEROS," "RatersDEROS" and "NextReportDue" in addition to the two fields listed in my expression below. I have the "DATEDIF" expression in those two fields. I want the "LastReport" field to be the trigger that enters either "COR" or "NA" in the field "NextReportDue." The criteria for "COR" is both fields must be 90-days or more, less than 90-days by either field will result in "NA." Here is my expression that I'm trying to use:

    =IIf([DaysSinceLastReport&NCOsDEROS]>90 And [DaysSinceLastReport&RatersDEROS]>90,"COR","NA").

    The problem is whenever I change the date in "LastReport", the result in "NextReportDue" does not change. It either stays at "COR" or "NA."

    Can you assist me with this?

  5. #5
    Join Date
    Jun 2002
    Location
    Saudi Arabia / Philippines
    Posts
    126
    I'm slightly bemused by your syntax - have the characters become garbled in your post or have I totally misunderstood the situation (always a strong possibility). The basic Iif syntax is correct but what are these brackets doing in the conditional part? As far as I know Access will interpret everything inside brackets as a name - field, control, form, whatever. Yet you have included an ampersand in that character string which makes me suspect that there is some intent at nested logic or arithmetic. I've just looked up again to see if there is some use of '&' of which I am unaware but Access help has no other use apart from the string concatenation function.

    Are you trying to add two values such as Iif(((value1 + value2) > 90) AND ((value3 + value4) > 90), true,false) I cannot agree more with the previous poster who implied that the more parentheses you use the less chance there is of falling foul of syntax defaults.

    Final point in my rambles: where are you using this expression? Be careful if you are using it in the On Format, On Print, On Current type events. Make sure that the values in the condition are what you expect. For example I often store a value from the previous row and use it to check contiguity in the succeeding row on a report. this works fine as long as you move forward through the report but fails on the first line of every page if you page backwards through the report.
    Last edited by Rod; 06-10-02 at 01:49.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •