Results 1 to 7 of 7
  1. #1
    Star Lounger
    Join Date
    Sep 2002
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Argument not optional (Access 2000)

    When clicking on the event Call KillObject(GPath, 0, "products"), i get the message argument not optional
    Can you tell me why ?


    Private Function KillObject(strDbName As String, acObjectType As Long, strObjectName As String, StrPassword As String)
    'Call KillObject(GPath, 0, "products")
    StrPassword = "secret"
    Dim db As DAO.Database
    Dim adb As Object
    Set adb = CreateObject("Access.Application")
    adb.OpenCurrentDatabase strDbName, , StrPassword
    adb.DoCmd.DeleteObject acObjectType, strObjectName
    adb.CloseCurrentDatabase
    Set adb = Nothing
    End Function


    Private Sub Command2_Click()
    Call KillObject(GPath, 0, "products")
    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Argument not optional (Access 2000)

    Your function KillObject has 4 arguments:
    strDbName
    acObjectType
    strObjectName
    strPassword

    But in your call to the function, you specify only the first three. You should also provide a password.

    If you want to be able to omit the password, define the function as

    Private Function KillObject(strDbName As String, acObjectType As Long, strObjectName As String, Optional strPassword As String)

  3. #3
    Star Lounger
    Join Date
    Sep 2002
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Argument not optional (Access 2000)

    Thank you for the reply. Yes, i also tried this but than i get the error "wrong number of arguments or invalid proprty assignment"

    Private Function KillObject(strDbName As String, acObjectType As Long, strObjectName As String, StrPassword As String)
    'Call KillObject(GPath, 0, "products")
    StrPassword = "secret"
    Dim db As DAO.Database
    Dim adb As Object
    Set adb = CreateObject("Access.Application")
    adb.OpenCurrentDatabase strDbName, , StrPassword
    adb.DoCmd.DeleteObject acObjectType, strObjectName
    adb.CloseCurrentDatabase
    Set adb = Nothing
    End Function


    Private Sub Command2_Click()
    Call KillObject(GPath, 0, "products", "secret")

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Argument not optional (Access 2000)

    Please see the thread starting at <post:=676,273>post 676,273</post:>.

    BTW, you must remove the line

    StrPassword = "secret"

    since you provide StrPassword as argument to the function.

  5. #5
    Star Lounger
    Join Date
    Sep 2002
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Argument not optional (Access 2000)

    Thank you Hans.I removed the line, and also i looked into the thread once again.After removing the line i get now again the old error " wrong number of arguments or invalid proprty assignment".
    You can see below that i followed your recomendations but defnitely i should have missed something. I think something is wrong with my entire code.

    Private Function KillObject(strDbName As String, acObjectType As Long, strObjectName As String, StrPassword As String)
    Dim db As DAO.Database
    Dim adb As Object
    Set adb = CreateObject("Access.Application")
    adb.OpenCurrentDatabase strDbName, , StrPassword
    adb.DoCmd.DeleteObject acObjectType, strObjectName
    adb.CloseCurrentDatabase
    Set adb = Nothing
    End Function


    Private Sub Command2_Click()
    Call KillObject(GPath, 0, "products", "secret")

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Argument not optional (Access 2000)

    The first reply in the thread I referred to contains links to two other posts. Please read those posts carefully. They show how to get around this error; the second post also explains why it occurs.

  7. #7
    Star Lounger
    Join Date
    Sep 2002
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Argument not optional (Access 2000)

    Just to let you know that i have taken into account all your remarks and i am grateful to you. My database is proper now

Posting Permissions

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