sql is a programming language with special purpose. Below is a detailed tutorial on setting the default value of SQL access that the editor has shared with you. Interested friends, let’s learn about it with the editor!
Brief description:
How to define field default values
question:
How to set the default value of a certain field in a table?
Method 1:
Use JETSQL to complete
ALTERTABLETABLENAMEALTERCOLUMNFIELDNAMETEXT(40)DEFAULT default value
Please note that the above statements should be executed using ADODB.CONNECTION.EXECUTE and other methods. If you directly use the above code to create a query that cannot be saved or run, you will get an ACCESS error message.
Method 2:
ADOX is OK.
FunctionChengTableFieldPro_ADO()
DimMyTableNameAsString
DimMyFieldNameAsString
DimGetFieldDesc_ADO
DimGetFieldDescription
MyTableName="ke_hu"
MyFieldName="dw_name"
DimMyDBAsNewADOX.Catalog
DimMyTableAsADOX.Table
DimMyFieldAsADOX.Column
OnErrorGoToErr_GetFieldDescription
MyDB.ActiveConnection=CurrentProject.Connection
SetMyTable=MyDB.Tables(MyTableName)
GetFieldDesc_ADO=MyTable.Columns(MyFieldName).Properties("Description")
DimproAsADODB.Property
ForEachproInMyTable.Columns(MyFieldName).Properties
Debug.Printpro.Name&":"&pro.Value&"-----type:"&pro.Type
Next
WithMyTable.Columns(MyFieldName)
'.Properties("nullable")=True'Required
'The above code cannot be set, the error message is:
'Multi-step OLEDB operation generates an error. If possible, check each OLEDB status value. No work was done.
'Currently, it can be set with the following statement:
'CurrentDb.TableDefs("ke_hu").Fields("DW_NAME").Properties("Required")=False
.Properties("JetOLEDB:AllowZeroLength")=True'Available empty
.Properties("default")="Silently default recognition"' default value
EndWith
SetMyDB=Nothing
Bye_GetFieldDescription:
ExitFunction
Err_GetFieldDescription:
Beep
Debug.PrintErr.Description
MsgBoxErr.Description,vbExclamation
GetFieldDescription=Null
ResumeBye_GetFieldDescription
EndFunction
Some references on "multi-step error":
SubChangeUnicode()
DimtdfAsTableDef
DimfldAsField
DimdbAsDatabase
DimproAsProperty
Setdb=CurrentDb
ForEachtdfIndb.TableDefs
ForEachfldIntdf.Fields
Ifffld.Type=dbTextThen
IfDBEngine.Errors(0).Number=3270Then
Setpro=fld.CreateProperty("UnicodeCompression",1,0)
fld.Properties.Appendp
EndIf
fld.Properties("UnicodeCompression")=True
EndIf
Nextfld
Nexttdf
EndSub
The above is a detailed tutorial on setting the default access value of SQL. I believe you have learned it. For more related content, please continue to pay attention to the wrong new technology channel.