spikepl
Eledittingent Beliped
- Local time
- Today, 08:48
- Joined
- Nov 3, 2010
- Messages
- 6,134
I am creating a table on the fly, and need for external reasons to format the Double field into STandard with 2 decimals. The code fails with Invalid operation.
What have I missed?
I have used the SetFieldProperty elsewhere on an existing table, and it worked just fine.
What have I missed?
I have used the SetFieldProperty elsewhere on an existing table, and it worked just fine.
Code:
Dim tbl As DAO.TableDef
Dim fld As DAO.Field
Dim fldprop As DAO.Property
If TableExists("tblKPI") Then
CurrentDb.TableDefs.Delete ("tblKPI")
End If
Set tbl = CurrentDb.CreateTableDef("tblKPI")
Set fld = tbl.CreateField("KPI", dbText)
tbl.Fields.Append fld
Set fld = tbl.CreateField("SOurce", dbText)
tbl.Fields.Append fld
rstSource.MoveFirst
Dim KortNavn As String
Dim myID As Long
While Not rstSource.EOF
myID = rstSource!StamdataID
KortNavn = DLookup("ShortName", "tblBasics", "BasicsID=" & myID)
Set fld = tbl.CreateField(ShortName, dbDouble)
[COLOR=Red] SetFieldProperty fld, "Format", dbText, "Standard"[/COLOR]
SetFieldProperty fld, "DecimalPlaces", dbInteger, 4
tbl.Fields.Append fld
rstSource.MoveNext
Wend
CurrentDb.TableDefs.Append tbl
Public Sub SetFieldProperty(ByVal fld As DAO.Field, ByVal strPropertyName As String, ByVal iDataType As DAO.DataTypeEnum, ByVal vValue As Variant)
Dim prp As DAO.Property
Set prp = Nothing
On Error Resume Next
Set prp = fld.Properties(strPropertyName)
On Error GoTo 0
If prp Is Nothing Then
Set prp = fld.CreateProperty(strPropertyName, iDataType, vValue)
[COLOR=Red] fld.Properties.Append prp[/COLOR] 'this gives Invalid operation
Else
prp.Value = vValue
End If
End Sub
Last edited: