Re: Adding Fields property DecimalPlaces using the fields collection



Hi Jeff,
what error do you get?
try like this:

dim fld as dao.field


set fld=ltdfDestination.CreateField(lfldSource.Name, lfldSource.Type)
Set lprpDestination = fld.CreateProperty("DecimalPlaces", dbByte, 0)
fld.Properties.Append lprpDestination
ltdfDestination.Fields.Append

this is how it works at me

as for Auto - i think it is the same as no DecimalPlaces defined, and property does not exists

--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com


"Aussie Jeff" <jeff@xxxxxxxxxxxxx> wrote in message news:OQN1wgJOHHA.5104@xxxxxxxxxxxxxxxxxxxxxxx
Alex

Thx for this. But this is an example straight from the help file. I have already tried this using a field definition and appending to the field properties collection. I can create the property but when I append it to the collection it produces an error.

Also I am not sure if the DecimalPlaces property is a dbInteger or dbLong or dbText field? I notice that in the design for a table the DecimalPlaces property can have a value of Auto or 0 thru to 15. Is Auto represented with -1?

I have posted my code below:-

Dim ldbsCurrent As DAO.Database

Dim lrstSource As DAO.Recordset
Dim lfldSource As DAO.Field
Dim lstrDestination As String
Dim lrstDestination As DAO.Recordset
Dim ltdfDestination As DAO.TableDef
Dim lprpDestination As DAO.Property
Dim lstrCurrentEntityClass As String
Dim lstrNewEntityClass As String

Set ldbsCurrent = CurrentDb()
Set lrstSource = ldbsCurrent.OpenRecordset("tblEntityFieldUsage")
lstrDestination = "tblXML_FieldUsage_Component"
Set ltdfDestination = ldbsCurrent.CreateTableDef(lstrDestination)

'using the source fields collection, create fields in the new table definition
For Each lfldSource In lrstSource.Fields
ltdfDestination.Fields.Append ltdfDestination.CreateField(lfldSource.Name, lfldSource.Type)
ltdfDestination.Fields(lfldSource.Name).AllowZeroLength = True
If lfldSource.Type = dbLong Then
'code fails here....
Set lprpDestination = ltdfDestination.Fields(lfldSource.Name).CreateProperty("DecimalPlaces", dbInteger, 0)
ltdfDestination.Fields(lfldSource.Name).Properties.Append lprpDestination
End If
Next

'append the new destination table to the tables collection and
'open a new recordset
ldbsCurrent.TableDefs.Append ltdfDestination
Set lrstDestination = ldbsCurrent.OpenRecordset(lstrDestination)

Maybe you or someone else can spot the mistake? (I have been staring at it for toooo long...)

cheers
Jeff

"Alex Dybenko" <alexdyb@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:ewCSHvHOHHA.2140@xxxxxxxxxxxxxxxxxxxxxxx
Hi,
you have to add property DecimalPlaces to this field. See below a sample to add property to database, this give you an idea, you can adjust it for field

--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com


Sub SetProperty(dbsTemp As Database, strName As String, _
booTemp As Boolean)

Dim prpNew As Property
Dim errLoop As Error

' Attempt to set the specified property.
On Error GoTo Err_Property
dbsTemp.Properties("strName") = booTemp
On Error GoTo 0

Exit Sub

Err_Property:

' Error 3270 means that the property was not found.

If DBEngine.Errors(0).Number = 3270 Then
' Create property, set its value, and append it to the
' Properties collection.
Set prpNew = dbsTemp.CreateProperty(strName, _
dbBoolean, booTemp)
dbsTemp.Properties.Append prpNew
Resume Next
Else
' If different error has occurred, display message.
For Each errLoop In DBEngine.Errors
MsgBox "Error number: " & errLoop.Number & vbCr & _
errLoop.Description
Next errLoop

End
End If

End Sub

"jeff" <jeff@work> wrote in message news:%23IwVZsGOHHA.4244@xxxxxxxxxxxxxxxxxxxxxxx
Hi gurus

I am using vb code to create a table and add fields. I need to set the DecimalPlaces property of a field to a value. I cannot see how to do this as it is not a "standard" attribute of the field object eg like fieldobject.AllowZeroLength = True where I want to fieldobject.DecimalPlaces=1

Can anyone help me with this...it is not so obvious in the online help...or am i missing something entirely??

cheers
Jeff





.



Relevant Pages


Loading