TableDef creation, Rich Text Field (Access 2007)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #1

    TableDef creation, Rich Text Field (Access 2007)

    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.

    Code:
    Public Sub createConTable()
    'Create the table for consequences
        
        Dim tblDef As TableDef
        Set tblDef = CurrentDb.CreateTableDef(strConTable, , , CurrentProject.Connection)
            
        With tblDef
            .Fields.Append .CreateField("KEY_Consequence", dbLong)
            .Fields.Append .CreateField("ID_Hazard", dbLong)
            .Fields.Append .CreateField("int_Number", dbInteger)
            .Fields.Append .CreateField("mem_Consequence", dbMemo)
            .Fields.Append .CreateField("mem_OLD_Consequence", dbMemo)
            .Fields.Append .CreateField("mem_Compare_Consequence", dbMemo)
           
        End With
        
        CurrentDb.TableDefs.Append tblDef
        
        
    'Cleanup
        Set tblDef = Nothing
            
    End Sub
    I have tried such things as:
    Code:
    .Fields("mem_Compare_Consequence").Properties("TextFormat")="Rich Text"
    without success.

    Any help is greatly appreciated.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    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.

    Comment

    • TheSmileyCoder
      Recognized Expert Moderator Top Contributor
      • Dec 2009
      • 2322

      #3
      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

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32669

        #4
        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 ;)

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          Try:
          Code:
          .Fields("mem_Compare_Consequence").Properties("TextFormat")=1

          Comment

          • TheSmileyCoder
            Recognized Expert Moderator Top Contributor
            • Dec 2009
            • 2322

            #6
            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:
            Code:
            Dim prp as DAO.Property
            With myTDF.Fields("mem_Compare_Action")
                        Set prp = f.CreateProperty("TextFormat", dbByte, 1) '1=acTextFormatHTMLRichText, constant only known in AC2007
                        .Properties.Append prp
            End With

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32669

              #7
              Originally posted by Smiley
              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 :)

              Comment

              Working...