Consulting

Results 1 to 7 of 7

Thread: Need Assistance with a complex If And Then statement

  1. #1
    VBAX Contributor
    Joined
    Jun 2008
    Location
    West Midlands
    Posts
    170
    Location

    Need Assistance with a complex If And Then statement

    Hi Guys,

    Once again I call on your collective wisdom to assist me on a coding issue,

    I will not go into the full details, but I am trying to construct a code line, current code is below;

    If Whoff > allo And Whoff >= rsstoreconday And rsconf_time <= "16:00" Then
    I have another variable to add into the mix, Cycday.

    My dilemma is this;

    Whoff will always be a value between 1 and 7, allo will always be a value between 1 and 7, rsstoreconday will always be a value between 1 and 7 and rsconf_time will be a time value between 06:00 to 22:00, the variable I want to add will always be a value between 1 and 17.

    I want to construct the code line as above but by adding in the variable Cycday, but to make the argument True if Cycday is greater than 7.

    If the code line returns a False argument then the routine adds 1 to the Cycday variable.

    I will attach the documents for you to check through, all the code lines work with the exception of the above which always returns a false argument which should otherwise be true if the Cycday variable was considered.

    I hope I have made sense...

    Thanking you in advance for your help.

    P.S. The Master Copy would be a much larger document with over 600 records but to simplify I have reduced to 2 records.
    Attached Files Attached Files

  2. #2
    VBAX Contributor
    Joined
    Jun 2008
    Location
    West Midlands
    Posts
    170
    Location
    I have since tried using an ElseIf statement but still cannot get it to work correctly;

    I have changed the time variable to a number.

    If Whoff > allo And Whoff = rsstoreconday And rsconf_time > "0.7" And cycday > 7 Then
                    ElseIf Whoff > allo And Whoff = rsstoreconday And rsconf_time <= "0.7" Then

  3. #3
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    I didn't test, but I think this is what you want.
    If (Whoff > allo And Whoff >= rsstoreconday And rsconf_time <= "16:00") OR Cycday > 7 Then 
    
    Else
       Cycday =Cycday+1
    endif
    Last edited by Tommy; 10-30-2015 at 09:15 AM. Reason: un wanted formatting was deleted.

  4. #4
    VBAX Contributor
    Joined
    Jun 2008
    Location
    West Midlands
    Posts
    170
    Location
    Tommy,

    Thank you for your response, this appears to have done the trick.

    I assume that the code line is checking to see if the statement inside the Brackets is True or False, if False then it checks the Or statement Line and if that is True then it performs the next code line rather than skipping to the End If, is this correct?

  5. #5
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    It is checking if either is true, if the first part is true it does not check the second part. If both parts are false then it executes the else statements.

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location
    Quote Originally Posted by Poundland View Post

    I want to construct the code line as above but by adding in the variable Cycday, but to make the argument True if Cycday is greater than 7.

    If the code line returns a False argument then the routine adds 1 to the Cycday variable.
    Just wondering if, given the logic of your statements in Post #1 whether we test the value of Cycday first to make the code quicker?

    If Cycday >7 or Whoff > all And Whoff  = rsstoreconday And rsconf_time > "0.7"
    Else
    Cycday = Cycday +1
    End If
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  7. #7
    VBAX Contributor
    Joined
    Jun 2008
    Location
    West Midlands
    Posts
    170
    Location
    Aussie,

    Thank you for your comment, I will check it out..

Posting Permissions

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