Results 1 to 8 of 8
  1. #1
    redkyte is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    9

    if statement not working

    Hi
    Why does the AND bit of my if statement not work?



    away = 0

    If rs!Stop_date < rs2!weekendings - 4 Then rs1!Mon = away and rs1!Mon = away

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    You statement makes no sense.
    each assignment must be on a separate line....
    if...then
    rst1= away
    rst1= aaway
    end if

    ...besides...why have the same statement

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,737

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    How do you know that it's not working?

    Then rs1!Mon = away and rs1!Mon = away

    Both parts of the Then Clause are assigning the same value to the same field! Perhaps the second 'And' part is supposed to be assigning a value to something other than the field named Mon?

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    redkyte is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    9
    Yep second Mon should have been Tue.
    Sorted it, many thanks.

  6. #6
    redkyte is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    9
    second Mon should have been Tue.
    Sorted it, many thanks.

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    As my signature says:

    The Devil's in the Details!


    Glad we could help!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Sorry ... I just can't stand it any more.

    If rs!Stop_date < rs2!weekendings - 4 Then rs1!Mon = away and rs1!Mon = away
    This is a very poorly written statement.

    To have multiple statements on a line, you must separate them using a colon
    If rs!Stop_date < rs2!weekendings - 4 Then rs1!Mon = away : rs1!Mon = away
    This still will not update fields "Mon" and "Tue". You cannot change the value of a field in a recordset without using "rs1.Edit" & "rs1.Update".

    There are two forms of the IF() function: the single line and the block form.
    The single line form has been depreciated: it was used back in the day when memory was expensive, processors were slow and you had to count bytes and cycles.

    In VBA you should always use the block form; there is no reason not to. The block form is much easier to read.
    This is the block form:
    Code:
        Away = 0
    
        If rs!Stop_date < rs2!weekendings - 4 Then
            rs1.Edit
            rs1!Mon = Away
            rs1!Tue = Away
            rs1.Update
        End If

    OK, off my rant.


    Having said all of that, the single line will work if you use this:
    Code:
        If rs!Stop_date < rs2!weekendings - 4 Then rs1.Edit: rs1!Mon = Away: rs1!Tue = Away: rs1.Update
    Note the colons in the line.

    As I said, not as easy to read/understand.......

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

Similar Threads

  1. IIF Statement isn't working
    By djclntn in forum Queries
    Replies: 9
    Last Post: 08-21-2013, 09:40 AM
  2. If statement not working
    By gkaro in forum Queries
    Replies: 10
    Last Post: 02-15-2012, 01:58 AM
  3. IIF Statement not working...
    By LanieB in forum Queries
    Replies: 6
    Last Post: 01-05-2012, 12:55 PM
  4. Replies: 1
    Last Post: 07-30-2011, 07:58 AM
  5. Textbox IIF statement not working
    By jgelpi16 in forum Forms
    Replies: 2
    Last Post: 08-22-2010, 08:41 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