Problem:
How do I set a field default value for a table?
Method One:
Using JET SQL to complete
Alter TABLE TableName ALTER COLUMN FIELDNAME TEXT default value
Please note that the above statements are ADODB. CONNECTION. Execute methods, and you can create a query that is not saved or run directly with the above code, and you get an error message from ACCESS.
Method Two:
ADOX can.
Function Chengtablefieldpro_ado ()
Dim Mytablename as String
Dim Myfieldname as String
Dim Getfielddesc_ado
Dim getfielddescription
Mytablename = "Ke_hu"
Myfieldname = "Dw_name"
Dim MyDB as New ADOX. Catalog
Dim MyTable as ADOX. Table
Dim MyField as ADOX. Column
Dim Pro as ADODB. Property
For each pro in Mytable.columns (Myfieldname). Properties
Debug.Print Pro. Name & ":" & Pro. Value & "----type:" & Pro. Type
Next
With Mytable.columns (Myfieldname)
'. Properties ("nullable") = True ' must be filled in
' Required cannot be set with the above code, the error message is:
' Multi-step OLE DB operation generated an error. If possible, check each OLE DB status value. No work is done.
' It can now be set with the following statement:
' Currentdb.tabledefs ("Ke_hu"). Fields ("Dw_name"). Properties ("Required") = False
. Properties ("Jet oledb:allow Zero Length") = True ' allows nulls
. Properties ("default") = "silently recognize and recognize" ' Default value
End With
Set MyDB = Nothing
Dim TDF as TableDef
Dim FLD as Field
Dim DB as Database
Dim Pro as Property
Set db = CurrentDb
For each TDF in db. TableDefs
For each fld in TDF. Fields
If fld. Type = Dbtext Then
If dbengine.errors (0). Number = 3270 Then
Set Pro = fld. CreateProperty ("UnicodeCompression", 1, 0)
Fld. Properties.append P
End If
Fld. Properties ("unicodecompression") = True
End If
Next FLD
Next TDF
End Sub
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.