Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set the Required property of a field 1

Status
Not open for further replies.

MangroBongacello

Programmer
Mar 20, 2001
189
SI
Hi,

how do I set the required property of a text field in Access database to false. I found info in another thread that suggests using

Column.Attributes=adColNullable

but I get an error message saying "The parameter is incorrect."

I need it when appending a new field to a table. This is the code:

tbl.Columns.Append "Fld1",adVarWChar,20
tbl.Columns("Fld1").Properties("Jet OLEDB: Allow Zero Length")=True
now how to set Required = False



Any ideas?

Thanks, Mangro
 

.Properties("Nullable") = True [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Thanx CCLINT, I figured it out myself later. But I have another problem. How to set the DefaultValue property?

.Properties("Default")=0 doesn't seem to work.

Thanx, Mangro
 
MangroBongacello: That should work.

What is happening then? (error, no change, etc.)

See


For other properties [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Is it a new table, or are you modifying an existing table? If modifying then the default will not be retrospective, so it will only work for new additions to the table
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
johnwm, MangroBongacello is Appending new fields....

But, anyways, yes, you can change this property for existing fields.

Please note that we are discussing the "Default" property, and not the Nullable property.

MangroBongacello: I cannot say right now what is causing this. [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
CCLINT and johnwm, thank you for your replies. I'm posting the part of procedure that deals with creating a table, perhaps there is something wrong with a way I'm doing this.

Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table

cat.ActiveConnection = MyConn

tbl.Name = "MyTable"
cat.Tables.Append tbl
tbl.Columns.Append "Fld1", adVarWChar, 8
tbl.Columns("Fld1").Properties("Jet OLEDB:Allow Zero Length") = True
tbl.Columns("Fld1").Properties("Nullable")=True
tbl.Columns.Append "Fld2", adDouble
tbl.Columns("Fld2").Properties("Default")=0


After this procedure is run, the table, fields, field's data types and properties are created and set up correctly accept the one in bold. It doesn't give me any error message, just nothing happens. I hope someone can spot a problem.

Thanx again, Mangro


 
MangroBongacello: I really believe you are erroring out on the line:
tbl.Columns("Fld1").Properties("Nullable")=True

Try the following, which will set the Nullable property before appending the field.
Then the next field should work:

Sub Createtable()
Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
Dim col As ADOX.Column


cat.ActiveConnection = conn

tbl.Name = "MyTable"
cat.Tables.Append tbl
Set col = New ADOX.Column

With col
Set .ParentCatalog = cat
.Name = "Fld1"
.Type = adVarWChar
.DefinedSize = 8
.Properties("Nullable") = True
.Properties("Jet OLEDB:Allow Zero Length") = True
tbl.Columns.Append col
End With

Set col = New ADOX.Column
With col
Set .ParentCatalog = cat
.Name = "Fld2"
.Type = adDouble
.Properties("Default") = 5
tbl.Columns.Append col
End With
Set cat = Nothing


End Sub [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top