Column Width

J

John

I have created a Database using DAO.

I use .Fields.Append .CreateField("Last Name", dbText, 90)
to create the fields. This all works OK except the column
width has not been set to the width I specified (i.e. 90).

When I look at my created database all of the columns in
the table are set to standard width. Presumably this is
overriding my specified amount.

Using DAO how do I turn off standard width on all of the
columns so that I can specify the amount?
 
D

Dan Artuso

Hi,
That argument is not for the column width, it's for the size in
bytes of a text field.
What you would have to do is create/modify the "ColumnWidth"
property of each Field object
 
J

John

Dan,

I have been trying to create/modify the "ColumnWidth" for
each field property (as you suggested) with no success.
Can you show me the code to get this to work?

Thanks
 
D

Dan Artuso

Hi,
Here you go. You should probably add to the error handling.

Dim dbs As Database, tdf As TableDef
Dim prpProperty As Property
Dim fld As DAO.Field
Const conErrPropertyNotFound = 3270


Set dbs = CurrentDb
Set tdf = dbs.TableDefs("tblBook")
Set fld = tdf.Fields("Code")
On Error Resume Next
fld.Properties("ColumnWidth") = 4000

If Err <> 0 Then
If Err <> conErrPropertyNotFound Then
On Error GoTo 0
MsgBox "Couldn't set property"
Else
On Error GoTo 0

Set prpProperty = fld.CreateProperty("ColumnWidth", _
dbInteger, 4000)
fld.Properties.Append prpProperty
End If
End If

fld.Properties.Refresh
 
D

Douglas J. Steele

It might be worth pointing out that the value of ColumnWidth is in twips,
where there are 1440 twips to the inch.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top