Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Required Property
Message
Information générale
Forum:
Visual Basic
Catégorie:
Bases de données DAO/RDO/ODBC/ADO
Divers
Thread ID:
00627999
Message ID:
00628104
Vues:
14
This message has been marked as the solution to the initial question of the thread.
>I am creating a new Access file with one table via ADOX. I have successfully generated the file, table and fields. Does anyone know how to set the Required property to "NO"? It seems to default to "YES".

Make sure you set a reference to Microsoft ADO Extension for DLL and Security (ADOX) in your project.
'sDBase: Path + Name of your database
'sTable: Name of the table to change
'sColumn: Name of the column to change
'iRequiredSize: The new size of the column
Sub ChangeColSize(sDBase As String, sTable As String, sColumn As String, iRequiredSize As Integer)
Dim cnn As New ADODB.Connection
Dim tbl As ADOX.Table
Dim cat As New ADOX.Catalog
Dim col As ADOX.Column
  cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sDBase & ";"
  cat.ActiveConnection = cnn
  Set tbl = cat.Tables(sTable)
  If tbl.Columns(sColumn).DefinedSize <> iRequiredSize Then
     Set col = New ADOX.Column
     col.Name = "TempCol"
     col.Type = adVarWChar
     col.DefinedSize = 255
     col.Attributes = adColNullable
     tbl.Columns.Append col
     col.Properties("Jet OLEDB:Allow Zero Length") = True
     cnn.Execute "UPDATE [" & sTable & "] SET [TempCol]=[" & sColumn & "]"
     tbl.Columns.Delete sColumn
     Set col = New ADOX.Column
     col.Name = sColumn
     col.Type = adVarWChar
     col.DefinedSize = 255
     col.Attributes = adColNullable
     tbl.Columns.Append col
     col.Properties("Jet OLEDB:Allow Zero Length") = True
     cnn.Execute "UPDATE [" & sTable & "] SET [" & sColumn & "]=[TempCol]"
     tbl.Columns.Delete "TempCol"
  End If
  Set col = Nothing
  Set tbl = Nothing
  Set cat = Nothing
  Set cnn = Nothing
End Sub
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform