Results 1 to 6 of 6
  1. #1
    joym is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2017
    Posts
    57

    Argument not optional and run time error 424

    I created the 2 codes below both worked while i directly wrote in as the control source in design view however when did this as an on click event i am having issues

    This code gets an error argument not optional
    Code:
    Private Sub txtDSE_Click()
    Me.txtDSE = IIf([Resolution Date And Time] > [txtRTF], Diff2Dates("ymdhn", [txtRTF], [Resolution Date And Time]))
    End If
    End Sub
    This code gets a run time error 424


    Code:
    Private Sub txtSS_Click()
    Me.txtSS = IIf([txtDSE] Is Null, "Within SLA", "SLA Exceeded")
    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    IIF has the arguments: IIF(condition, TrueResult, FalseResult)

    you left off the false
    IIf([Resolution Date And Time] > [txtRTF],
    Diff2Dates("ymdhn", [txtRTF], [Resolution Date And Time])
    , falseValue)

    and you dont need ENDIF. IIF is selfcontained.

  3. #3
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    1. First line, Is txtRTF a date value?
    2. What are you trying to do here: Diff2Dates("ymdhn", [txtRTF]

    3. Second line maybe, IIf(Isnull([txtDSE]), "Within SLA", "SLA Exceeded")


  4. #4
    joym is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2017
    Posts
    57
    thanks worked like a charm
    Last edited by joym; 03-01-2017 at 02:51 PM.

  5. #5
    joym is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2017
    Posts
    57
    Quote Originally Posted by Bulzie View Post
    1. First line, Is txtRTF a date value?
    2. What are you trying to do here: Diff2Dates("ymdhn", [txtRTF]
    The diff2date is a module I created that subtracts time and displays the difference

    Quote Originally Posted by Bulzie View Post
    3. Second line maybe, IIf(Isnull([txtDSE]), "Within SLA", "SLA Exceeded")
    this partially worked however it only displays SLA Exceeded even if txtDSE is empty


  6. #6
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    To avoid the possibility that Access considers the control reference to be ambiguous, use the full control reference:
    IIf(Isnull(Me![txtDSE]), "Within SLA", "SLA Exceeded")
    If you're allowing and have empty strings in the table field, you'll have to test for both Null and zero length strings but I'm not sure what you mean by empty. Empty has a specific meaning that applies to a declared object variable that contains no object.
    You might need to have a function as the control source, but IIRC, you cannot do this if the control is bound
    Code:
    If IsNull(Me!txtDSE) Then
      something = "Within SLA"
    Else
      somethingElse = "SLA Exceeded"
    End If
    I guess you could do a nested IIF to test for both, but I try to avoid those as much as possible.

    The reason for the error before is that Is Null is for queries; IsNull() is a vba function.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Compile Error: Argument not optional
    By Nadine67 in forum Access
    Replies: 5
    Last Post: 08-02-2015, 03:09 PM
  2. error argument not optional
    By slimjen in forum Programming
    Replies: 10
    Last Post: 03-20-2013, 09:31 PM
  3. Compile Error: Argument not optional
    By tariq1 in forum Programming
    Replies: 4
    Last Post: 08-11-2012, 01:06 PM
  4. Replies: 7
    Last Post: 11-17-2011, 02:56 PM
  5. Compile Error: Argument Not Optional
    By bg18461 in forum Access
    Replies: 1
    Last Post: 12-01-2010, 08:47 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