By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,124 Members | 1,567 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,124 IT Pros & Developers. It's quick & easy.

TableDef creation, Rich Text Field (Access 2007)

TheSmileyCoder
Expert Mod 100+
P: 2,321
I need to create a table, where one of the memo fields shall be a Rich Text field. Can anyone help me with that? This is the code I currently have.

Expand|Select|Wrap|Line Numbers
  1. Public Sub createConTable()
  2. 'Create the table for consequences
  3.  
  4.     Dim tblDef As TableDef
  5.     Set tblDef = CurrentDb.CreateTableDef(strConTable, , , CurrentProject.Connection)
  6.  
  7.     With tblDef
  8.         .Fields.Append .CreateField("KEY_Consequence", dbLong)
  9.         .Fields.Append .CreateField("ID_Hazard", dbLong)
  10.         .Fields.Append .CreateField("int_Number", dbInteger)
  11.         .Fields.Append .CreateField("mem_Consequence", dbMemo)
  12.         .Fields.Append .CreateField("mem_OLD_Consequence", dbMemo)
  13.         .Fields.Append .CreateField("mem_Compare_Consequence", dbMemo)
  14.  
  15.     End With
  16.  
  17.     CurrentDb.TableDefs.Append tblDef
  18.  
  19.  
  20. 'Cleanup
  21.     Set tblDef = Nothing
  22.  
  23. End Sub
I have tried such things as:
Expand|Select|Wrap|Line Numbers
  1. .Fields("mem_Compare_Consequence").Properties("TextFormat")="Rich Text"
without success.

Any help is greatly appreciated.
Jul 2 '10 #1

✓ answered by TheSmileyCoder

I found out what to do. The problem is that the property for textformat couldn't be found, unless I had manually created it first (by manually entering table design view and setting it to rich text). Whether this is because Access per default does not create the property, until it is used the first time, or if its because this local table, is generated from a linked access 2000 table in a Access.

Now this is what I did:
Expand|Select|Wrap|Line Numbers
  1. Dim prp as DAO.Property
  2. With myTDF.Fields("mem_Compare_Action")
  3.             Set prp = f.CreateProperty("TextFormat", dbByte, 1) '1=acTextFormatHTMLRichText, constant only known in AC2007
  4.             .Properties.Append prp
  5. End With

Share this Question
Share on Google+
6 Replies


NeoPa
Expert Mod 15k+
P: 31,761
Is this something you've managed to do manually first Smiley? I have to say that, from my research (2003 only mind you), a Memo field takes plain text data only.
Jul 2 '10 #2

TheSmileyCoder
Expert Mod 100+
P: 2,321
Access 2007 has built in support for rich text field. A memo field can in that case be either "Plain Text" or "Rich Text". You can manually set the field in design view, but im not one for doing stuff manually :P
Jul 2 '10 #3

NeoPa
Expert Mod 15k+
P: 31,761
I wouldn't suggest it :D

I was merely asking, as that is often a very good indicator of what is available to do via code.

I'm afraid this seems to be veering into 2007 specific territory, where I drown if I go in too far ;)
Jul 2 '10 #4

ADezii
Expert 5K+
P: 8,692
Try:
Expand|Select|Wrap|Line Numbers
  1. .Fields("mem_Compare_Consequence").Properties("TextFormat")=1
Jul 2 '10 #5

TheSmileyCoder
Expert Mod 100+
P: 2,321
I found out what to do. The problem is that the property for textformat couldn't be found, unless I had manually created it first (by manually entering table design view and setting it to rich text). Whether this is because Access per default does not create the property, until it is used the first time, or if its because this local table, is generated from a linked access 2000 table in a Access.

Now this is what I did:
Expand|Select|Wrap|Line Numbers
  1. Dim prp as DAO.Property
  2. With myTDF.Fields("mem_Compare_Action")
  3.             Set prp = f.CreateProperty("TextFormat", dbByte, 1) '1=acTextFormatHTMLRichText, constant only known in AC2007
  4.             .Properties.Append prp
  5. End With
Sep 16 '10 #6

NeoPa
Expert Mod 15k+
P: 31,761
Smiley:
Whether this is because Access per default does not create the property, until it is used the first time, or if its because this local table, is generated from a linked access 2000 table in a Access.
It's the former Smiley. I've come across something similar in the past where it was necessary to create and add the property (I forget which) to the object's collection before it could be accessed, so this is not unique in that respect. I believe it was for Unicode Compression of a text field in a table. I've only ever played in that sort of area once, but I remember it being very hard to work out what was going on and what was required to get past it.

Well done for solving anyway :)
Sep 16 '10 #7

Post your reply

Sign in to post your reply or Sign up for a free account.