Results 1 to 6 of 6
  1. #1
    Lynn is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2010
    Posts
    25

    Nested If Expressions

    Hi,
    I have an unbounded control on my form and I want to have a nested if expression attached to it.

    I have three radio buttons: Approved, Denied and Accepted. I also have two fields: DateOfCommunication and Timeframe.

    Here's what I came up with for a nested statement. Suffice it to say that it doesn't work...



    =IIF([Approved] = True Or [Accepted] = True, (IIF([Timeframe] = "6 months", DateAdd("m",6,[DateOfCommunication]),DateAdd("m", 12, [DateOfCommunication])), Null)

    So in effect I'm wanting the expression to figure out a date in the control if Approved or Accepted is clicked and no value in the control if Denied is clicked.

    Am I even close?
    Lynn

  2. #2
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931

    Option Group

    This is What I infer from your post.

    You Have three options:
    1) Approved
    2) Accepted
    2) Denied

    You have a Field Timeframe and DateOfCommunication

    Now here is what you want to do:
    1) When Approved is Checked: Resultant Date will be a date 6 months from the Date of Communication.
    2) When Accepted is Checked: Resultant Date will be a date 12 months from the Date of Communication.
    3) When Denied is selected: Resultant Date is Null.

    I also assume these are not multiselection options which means user will not be required to check two options at and point.

    My solution is not independent check box but an option group the code used as follows:
    Private Sub frmOption_AfterUpdate()
    Select Case Me.frmOption
    Case Is = 1
    Me.Text11 = DateAdd("m", 6, Me.Text9)
    Case Is = 2
    Me.Text11 = DateAdd("m", 12, Me.Text9)
    Case Is = 3
    Me.Text11 = vbNullString
    End Select
    End Sub

    Attached is an mdb. Please refer to the same.

    Mark this thread solved if this solves your problem.

  3. #3
    Lynn is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2010
    Posts
    25
    Hi,
    That's a great help, thank you. Just to clarify though:
    1) When Approved or Accepted is checked, the resulting date will depend on whether "6 months" or "12 months" is keyed into the Timeframe field. So I'd input as follows:

    Click Approved or Accepted, then enter in [Timeframe] either "6 months" or "12 months" and the resulting date would calculate.

    2) When Denied is checked, the resulting date field is null, as you have it above. so:

    Click Denied, resulting date field would be blank whether I inputted something in [Timeframe] or not.

    Thanks,
    Lynn

  4. #4
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Same setup but enhanced the code a little bit.
    Scope of the Code:

    1) Check if Date of Communication is Blank if yes you will get a prompt.
    2) Check if Time Frame is blank if yes you will get a prompt.
    3) Verifies whether Time frame is either 6 or 12 if not you will get an error prompt.
    4) if Denied is Selected clears result date and time frame.
    5) if contditions are not met the option group remains unselected i.e. if you click Approved and conditions are not meet the option is not selected this means that after filling in valid data into the fields you can straight away select Approved you don't have to select some other option and then select approved.

    Code:


    Private Sub frmOption_AfterUpdate()
    Select Case Me.frmOption
    Case Is = 1
    If IsNull(Me.Text9) Then
    MsgBox "Please Type Date of Communication", vbInformation, "Type Date of Communication"
    Me.frmOption = 0
    ElseIf IsNull(Me.Text13) Then
    MsgBox "Please type a time frame", vbInformation, "Time Frame not Entered"
    Me.frmOption = 0
    ElseIf Me.Text13 <> 6 And Me.Text13 <> 12 Then
    MsgBox "Time frame has to be either 6 months or 12 months", vbInformation, "Invalid Time Frame"
    Me.frmOption = 0
    Else
    Me.Text11 = DateAdd("m", Me.Text13, Me.Text9)
    End If
    Case Is = 2
    If IsNull(Me.Text9) Then
    MsgBox "Please Type Date of Communication", vbInformation, "Type Date of Communication"
    Me.frmOption = 0
    ElseIf IsNull(Me.Text13) Then
    MsgBox "Please type a time frame", vbInformation, "Time Frame not Entered"
    Me.frmOption = 0
    ElseIf Me.Text13 <> 6 And Me.Text13 <> 12 Then
    MsgBox "Time frame has to be either 6 months or 12 months", vbInformation, "Invalid Time Frame"
    Me.frmOption = 0
    Else
    Me.Text11 = DateAdd("m", Me.Text13, Me.Text9)
    End If
    Case Is = 3
    Me.Text11 = vbNullString
    Me.Text13 = Null
    End Select
    End Sub


    if this solves your problem mark the thread solved.

  5. #5
    Lynn is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2010
    Posts
    25
    It would have taken me forever to figure this out. Thanks so much!
    Lynn

  6. #6
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    I am glad this code helped you happy accessing

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

Similar Threads

  1. Combining Two DCount expressions in one
    By nmodhi in forum Forms
    Replies: 1
    Last Post: 02-26-2010, 10:49 AM
  2. Conditions / Expressions
    By Mark344 in forum Access
    Replies: 1
    Last Post: 02-19-2010, 08:15 AM
  3. (simple) Expressions give error message
    By P.Hofman in forum Forms
    Replies: 3
    Last Post: 01-21-2010, 01:57 AM
  4. Unsafe expressions are not blocked.
    By darksniperx in forum Access
    Replies: 8
    Last Post: 01-07-2010, 03:25 PM
  5. Nested Joins
    By zephaneas in forum Programming
    Replies: 0
    Last Post: 11-10-2008, 11:49 AM

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