Create table with Hyperlink field

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Greg Strong

    #1

    Create table with Hyperlink field

    Hello All,

    Ok I've read it is not necessarily a good ideal to create a hyperlink
    field in a database, but I've tried. I've also read that a hyperlink
    field is a memo field with attributes of dbHyperlinkFiel d +
    dbVariableField . So I tried using the code below, and received the error
    below. Any ideals? Thanks!

    ,----- [ Error message on 'db.TableDefs.A ppend tdf' ]
    | Run-time error '3010':
    |
    | Table 'Supplier' already exists.
    `-----

    =============== ======>Begin Code>========== =============== ==========>
    Sub CreateSuppliers WithHyperLink()
    Dim db As DAO.Database
    Dim tdf As DAO.TableDef
    Dim fld As DAO.Field

    Set db = CurrentDb()
    Set tdf = db.CreateTableD ef("Suppliers" )

    With tdf
    .Fields.Append .CreateField("S upplierID", dbLong)
    .Fields.Append .CreateField("C ompanyName", dbText, 40)
    .Fields.Append .CreateField("C ontactName", dbText, 30)
    .Fields.Append .CreateField("C ontactTitle", dbText, 30)
    .Fields.Append .CreateField("A ddress", dbText, 60)
    .Fields.Append .CreateField("C ity", dbText, 15)
    .Fields.Append .CreateField("R egion", dbText, 15)
    .Fields.Append .CreateField("P ostalCode", dbText, 10)
    .Fields.Append .CreateField("C ountry", dbText, 15)
    .Fields.Append .CreateField("P hone", dbText, 24)
    .Fields.Append .CreateField("F ax", dbText, 24)
    .Fields.Append .CreateField("H omepage", dbMemo)

    For Each fld In .Fields
    If fld.name = "Homepage" Then
    Debug.Print "ok your in the loop"
    fld.Attributes = dbHyperlinkFiel d + dbVariableField
    End If
    Next fld

    End With

    db.TableDefs.Ap pend tdf

    Set fld = Nothing
    Set tdf = Nothing
    Set db = Nothing
    RefreshDatabase Window

    End Sub
    =============== ======<End Code<========== =============== ==========<

    --
    Regards,

    Greg Strong
  • Br@dley

    #2
    Re: Create table with Hyperlink field

    Greg Strong wrote:[color=blue]
    > Hello All,
    >
    > Ok I've read it is not necessarily a good ideal to create a hyperlink
    > field in a database, but I've tried. I've also read that a hyperlink
    > field is a memo field with attributes of dbHyperlinkFiel d +
    > dbVariableField . So I tried using the code below, and received the
    > error below. Any ideals? Thanks!
    >
    > ,----- [ Error message on 'db.TableDefs.A ppend tdf' ][color=green]
    >> Run-time error '3010':
    >>
    >> Table 'Supplier' already exists.[/color][/color]

    So, the table exists already. Delete it and try again???

    <>

    --
    regards,

    Br@dley


    Comment

    • Allen Browne

      #3
      Re: Create table with Hyperlink field

      Greg, I suspect this is an issue of timing.

      Try setting the attributes before appending the field to the table's Fields
      collection:

      Set fld = .CreateField("H omePage", dbMemo)
      fld.Attributes = dbHyperlinkFiel d + dbVariableField
      .Append fld
      --
      Allen Browne - Microsoft MVP. Perth, Western Australia.
      Tips for Access users - http://allenbrowne.com/tips.html
      Reply to group, rather than allenbrowne at mvps dot org.

      "Greg Strong" <NoJunk@NoJunk4 U².com> wrote in message
      news:tfbs125b06 s1vuv4srbb383c2 9g139tvjb@4ax.c om...[color=blue]
      > Hello All,
      >
      > Ok I've read it is not necessarily a good ideal to create a hyperlink
      > field in a database, but I've tried. I've also read that a hyperlink
      > field is a memo field with attributes of dbHyperlinkFiel d +
      > dbVariableField . So I tried using the code below, and received the error
      > below. Any ideals? Thanks!
      >
      > ,----- [ Error message on 'db.TableDefs.A ppend tdf' ]
      > | Run-time error '3010':
      > |
      > | Table 'Supplier' already exists.
      > `-----
      >
      > =============== ======>Begin Code>========== =============== ==========>
      > Sub CreateSuppliers WithHyperLink()
      > Dim db As DAO.Database
      > Dim tdf As DAO.TableDef
      > Dim fld As DAO.Field
      >
      > Set db = CurrentDb()
      > Set tdf = db.CreateTableD ef("Suppliers" )
      >
      > With tdf
      > .Fields.Append .CreateField("S upplierID", dbLong)
      > .Fields.Append .CreateField("C ompanyName", dbText, 40)
      > .Fields.Append .CreateField("C ontactName", dbText, 30)
      > .Fields.Append .CreateField("C ontactTitle", dbText, 30)
      > .Fields.Append .CreateField("A ddress", dbText, 60)
      > .Fields.Append .CreateField("C ity", dbText, 15)
      > .Fields.Append .CreateField("R egion", dbText, 15)
      > .Fields.Append .CreateField("P ostalCode", dbText, 10)
      > .Fields.Append .CreateField("C ountry", dbText, 15)
      > .Fields.Append .CreateField("P hone", dbText, 24)
      > .Fields.Append .CreateField("F ax", dbText, 24)
      > .Fields.Append .CreateField("H omepage", dbMemo)
      >
      > For Each fld In .Fields
      > If fld.name = "Homepage" Then
      > Debug.Print "ok your in the loop"
      > fld.Attributes = dbHyperlinkFiel d + dbVariableField
      > End If
      > Next fld
      >
      > End With
      >
      > db.TableDefs.Ap pend tdf
      >
      > Set fld = Nothing
      > Set tdf = Nothing
      > Set db = Nothing
      > RefreshDatabase Window
      >
      > End Sub
      > =============== ======<End Code<========== =============== ==========<
      >
      > --
      > Regards,
      >
      > Greg Strong[/color]


      Comment

      • Greg Strong

        #4
        Re: Create table with Hyperlink field

        On Mon, 20 Mar 2006 16:17:28 +1100, "Br@dley" <dontlookforme@ google.com>
        wrote:
        [color=blue]
        >So, the table exists already. Delete it and try again???[/color]

        It is deleted. I should have originally stated this explicitly. This is
        why the error message is so strange. In the procedure that I run, I
        delete all of the relationships and tables, then start from scratch.

        Thanks!
        --
        Regards,

        Greg Strong

        Comment

        • Greg Strong

          #5
          Re: Create table with Hyperlink field

          On Mon, 20 Mar 2006 13:59:12 +0800, "Allen Browne"
          <AllenBrowne@Se eSig.Invalid> wrote:
          [color=blue]
          >Try setting the attributes before appending the field to the table's Fields
          >collection:
          >
          > Set fld = .CreateField("H omePage", dbMemo)
          > fld.Attributes = dbHyperlinkFiel d + dbVariableField
          > .Append fld[/color]

          I used your suggestion. It worked. The short answer is I think that I
          may have had some conflicts with references set in my working copy of
          NorthWind which is where I was doing some testing. After dumping module,
          and re-importing module into fresh NW, then the code worked. The main
          reason was I did this was because I couldn't find a way to create a
          hyperlink field type using DDL running from code. FWIW the code is
          below.

          Thanks!

          --
          Regards,

          Greg Strong

          =============== ======>Begin Code>========== =============== ==========>
          Sub CreateSuppliers WithHyperLink()
          Dim db As DAO.Database
          Dim tdf As DAO.TableDef
          Dim fldSupplierID As DAO.Field
          Dim fldCompanyName As DAO.Field
          Dim fldContactName As DAO.Field
          Dim fldContactTitle As DAO.Field
          Dim fldAddress As DAO.Field
          Dim fldCity As DAO.Field
          Dim fldRegion As DAO.Field
          Dim fldPostalCode As DAO.Field
          Dim fldCountry As DAO.Field
          Dim fldPhone As DAO.Field
          Dim fldFax As DAO.Field
          Dim fldHomepage As DAO.Field

          Set db = CurrentDb()

          On Error Resume Next
          ' Delete the table if it already exists.
          db.TableDefs.De lete "Suppliers"
          On Error GoTo 0

          Set tdf = db.CreateTableD ef()
          tdf.name = "Suppliers"

          Set fldSupplierID = tdf.CreateField ("SupplierID ", dbLong)
          Set fldCompanyName = tdf.CreateField ("CompanyNam e", dbText, 40)
          Set fldContactName = tdf.CreateField ("ContactNam e", dbText, 30)
          Set fldContactTitle = tdf.CreateField ("ContactTitle" , dbText, 30)
          Set fldAddress = tdf.CreateField ("Address", dbText, 60)
          Set fldCity = tdf.CreateField ("City", dbText, 15)
          Set fldRegion = tdf.CreateField ("Region", dbText, 15)
          Set fldPostalCode = tdf.CreateField ("PostalCode ", dbText, 10)
          Set fldCountry = tdf.CreateField ("Country", dbText, 15)
          Set fldPhone = tdf.CreateField ("Phone", dbText, 24)
          Set fldFax = tdf.CreateField ("Fax", dbText, 24)
          Set fldHomepage = tdf.CreateField ("Homepage", dbMemo)
          fldHomepage.Att ributes = dbHyperlinkFiel d + dbVariableField

          With tdf.Fields
          .Append fldSupplierID
          .Append fldCompanyName
          .Append fldContactName
          .Append fldContactTitle
          .Append fldAddress
          .Append fldCity
          .Append fldRegion
          .Append fldPostalCode
          .Append fldCountry
          .Append fldPhone
          .Append fldFax
          .Append fldHomepage
          End With

          With db.TableDefs
          .Append tdf
          .Refresh
          End With

          Set fldSupplierID = Nothing
          Set fldCompanyName = Nothing
          Set fldContactName = Nothing
          Set fldContactTitle = Nothing
          Set fldContactTitle = Nothing
          Set fldAddress = Nothing
          Set fldCity = Nothing
          Set fldRegion = Nothing
          Set fldPostalCode = Nothing
          Set fldCountry = Nothing
          Set fldPhone = Nothing
          Set fldFax = Nothing
          Set fldHomepage = Nothing
          Set tdf = Nothing
          Set db = Nothing
          Application.Ref reshDatabaseWin dow

          End Sub
          =============== ======<End Code<========== =============== ============<

          Comment

          Working...