Reputation: 559
I'm creating a table with a memo field in DAO. However, I don't know how to set/create the rich text property for the field.
The following code gives a run time error:
Sub CreateTable()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field2
Set db = CurrentDb
' Create table
Set tdf = db.CreateTableDef
tdf.Name = "myTable"
Set fld = tdf.CreateField("memo_field", dbMemo)
fld.Properties("TextFormat").Value = acTextFormatHTMLRichText '<- getting error here
tdf.Fields.Append fld
db.TableDefs.Append tdf
db.TableDefs.Refresh
Application.RefreshDatabaseWindow
Set fld = Nothing
Set tdf = Nothing
Set db = Nothing
End Sub
Somebody in a forum suggested something like this,
fld.Properties.Append fld.CreateProperty("TextFormat", dbByte, acTextFormatHTMLRichText)
but I was not able to implement this. I guess I just go the syntax wrong. What would be the correct way to implement this? Thanks for your help!
Upvotes: 1
Views: 1109
Reputation: 3991
You may have trouble appending a property to a field that is not yet appended to a TableDef
.
Try:
Set fld = tdf.CreateField("memo_field", dbMemo)
tdf.Fields.Append fld
tdf.Fields(fld.Name).Properties.Append fld.CreateProperty("TextFormat", dbByte, acTextFormatHTMLRichText)
Upvotes: 3