Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Burgas, Bulgaria
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Items not found (Access 2000)

    Can you help me set straight the error Items not found in this collection appearing with the folowing function:
    Private Function adhoc()
    On Error GoTo ErrProc
    Dim StrPassword As String
    StrPassword = "sally"
    Dim wsp As DAO.Workspace
    Dim dbs As DAO.Database
    Dim tdf As DAO.TableDef
    Dim fld As DAO.Field
    Dim prp As DAO.Property
    Set wsp = DAO.DBEngine.Workspaces(0)
    Set dbs = wsp.OpenDatabase("C:MyDocumentsMeads.mdb", False, False, ";PWD=" & StrPassword)
    ' create the field ContractDate
    Set tdf = dbs.TableDefs("Customers")
    Set fld = tdf.Fields("ContractDate")
    Set prp = fld.CreateProperty("Format", dbText, "Short Date")
    fld.Properties.Append prp
    tdf.Fields.Refresh
    dbs.Close
    Set fld = Nothing
    Set tdf = Nothing
    Set dbs = Nothing
    Set wsp = Nothing
    Exit Function
    ErrProc:
    If Err = 3191 Then
    Resume Next
    Else
    MsgBox Err.Description ' or something else you want
    End If
    End Function

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

    Re: Items not found (Access 2000)

    You haven't told us on which line the error occurs. The error "Item not found in this collection" means that you refer to a non-existing member of a collection. Possibilities are:
    - The table Customers doesn't exist in that database
    - The field ContractDate doesn't exist in the Customers table.

  3. #3
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Burgas, Bulgaria
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Items not found (Access 2000)

    Unfortunately Access does not point to the line where the error occurs.The table Customers exists in the database, however the field ContractDate doesnt exists and i want to add it by the function i have created.Surely i miss something ?

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

    Re: Items not found (Access 2000)

    But your code doesn't create the field, it refers to it as if it already exists. If you want to create the field, replace the line

    Set fld = tdf.Fields("ContractDate")

    with the following:

    Set fld = tdf.CreateField("ContractDate", dbDate)
    tdf.Fields.Append fld

  5. #5
    3 Star Lounger
    Join Date
    Feb 2004
    Location
    Burgas, Bulgaria
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Items not found (Access 2000)

    Thanks a lot ,i have created already the field and i am very grateful for that.Thank you

Posting Permissions

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