Results 1 to 11 of 11
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    error argument not optional


    All, Using 2010 working on a 2003 database. Have code to enable and disable bypass.
    Code:
    Public Function SetProperties(strPropName As String, _
    varPropType As Variant, varPropValue As Variant) As Integer
        On Error GoTo Err_SetProperties
        Dim db As DAO.Database, prp As DAO.Property
        Set db = CurrentDb
        db.Properties(strPropName) = varPropValue
        SetProperties = True
        Set db = Nothing
    Exit_SetProperties:
        Exit Function
    Err_SetProperties:
        If Err = 3270 Then    'Property not found
            Set prp = db.CreateProperty(strPropName, varPropType, varPropValue)
            db.Properties.Append prp
            Resume Next
        Else
            SetProperties = False
            MsgBox "SetProperties", Err.Number, Err.Description
            Resume Exit_SetProperties
        End If
    End Function
    I was able to debug and compile. But when I call this function; I get a compile error "Arguement not optional."
    Why the compile error if I was able to debug and compile and how can I fix this error. I need it before I create the .mde.
    Thanks

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Where are you calling this function? Show that code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    I was testing it so calling it in the immediate window below the function code.

  4. #4
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Call SetProperties

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    The function has 3 arguments, all are required. So must call it with some values for each argument.

    SetProperties(value1, value2, value3)

    It compiles because the Call is not anywhere in code or query or textbox. It isn't anywhere until you use it in the Immediate window. The Call errors, not the function.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    I tested this a month ago in another database and it worked with only calling the name of the function. actually; I always call the function with call "whatever". Is it because Im not calling it from somewhere else other than the module? I don't understand. thanks

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    I have never known a function to run without input when argument required. If optional would be different.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    ok. I do remember that I didn't not use option explicit in the module. Do you think this is why I was able to run this a month ago? Im trying to make my code better by using option explicit in all my forms and modules. Especially when I plan to deploy mdes. So; how do I call the function. Thanks.

  9. #9
    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,848

  10. #10
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Got it. Thanks so much

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Option Explicit has nothing to do with calling function with or without required arguments. It does require that variables be declared before they are used in code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 2
    Last Post: 10-23-2012, 12:18 PM
  2. table field name "Year" causing Argument Not Optional
    By JosmithTwo in forum Programming
    Replies: 2
    Last Post: 09-26-2012, 08:01 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