Results 1 to 2 of 2
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Indexed field... (2000 sr 1)

    This macro make a new table in the mdb.
    I have undestand how to insert this param:

    adInteger
    adVarWChar
    adCurrency
    .Keys.Append "PrimaryKeyItemID", adKeyPrimary, "CAMPO01" ' DEFINISCE CHIAVE PER IL CAMPO ItemID

    but to insert indexed with accept duplicate in CAMPO02, how make this?

    =========================
    Option Explicit
    Sub CreateTable()
    Dim adoxCatalog As ADOX.Catalog
    Dim adoxTable As ADOX.Table
    Dim adoCN As ADODB.Connection

    'Establish connection to the database
    Set adoCN = New Connection
    With adoCN
    .Provider = "Microsoft.Jet.OLEDB.4.0" '4.0 for Access 2000, 3.51 for Access 97
    .ConnectionString = strDatabase
    .Open
    End With


    'Now associate our connection to a Catalog object
    Set adoxCatalog = New ADOX.Catalog
    Set adoxCatalog.ActiveConnection = adoCN


    'Create the table definition
    Set adoxTable = New ADOX.Table
    With adoxTable
    .Name = "NUOVA_TABELLA"
    .Columns.Append "CAMPO01", adInteger ' NUMERICO, INTERO LUNGO
    .Columns.Append "CAMPO02", adVarWChar, 100 ' TESTO LUNG 100
    .Columns.Append "CAMPO03", adCurrency ' VALUTA
    .Keys.Append "PrimaryKeyItemID", adKeyPrimary, "CAMPO01" ' DEFINISCE CHIAVE PER IL CAMPO ItemID
    End With

    'Append the table to the database
    adoxCatalog.Tables.Append adoxTable

    'Clean up and close

    End Sub

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

    Re: Indexed field... (2000 sr 1)

    You want to create an index, not a key

    ...
    .Columns.Append "CAMPO03", adCurrency ' VALUTA
    Dim idx As New ADOX.Index
    ' Define an index
    idx.Name = "CAMPO01Index"
    ' Add a field to the index
    idx.Columns.Append "CAMPO01"
    ' Append the index to the table
    .Indexes.Append idx
    End With
    ...

Posting Permissions

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