Share via

Add Hyperlink field to linked Access table using VBA

Anonymous
2015-10-01T21:58:18+00:00

I need to add a hyperlink field to an existing linked table using VBA in Access. The field gets created, but when I try to change the attribute to Hyperlink, I get an error. Is it not possible to set a hyperlink attribute on an existing table? Any ideas?

Code:

'dbs is the linked database

With dbs

   Set tdf = .TableDefs!tblTest

      With tdf

         .Fields.Append .CreateField("WebsiteURL", dbMemo)

         .Fields("WebsiteURL") .Attributes = dbHyperlinkField    <<== It fails here with message Error 3219 Invalid Operation

      End With

End With

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
2015-10-02T03:48:45+00:00

Second, this works for me:

    Dim dbs         As DAO.Database

    Dim tdf         As DAO.TableDef

    Dim fld         As DAO.Field

    Set dbs = CurrentDb

    With dbs

        Set tdf = .TableDefs!Employees

        With tdf

            Set fld = .CreateField("WebsiteURL", dbMemo)

            fld.Attributes = dbHyperlinkField Or dbVariableField

            .fields.Append fld

        End With

    End With

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2015-10-02T13:57:50+00:00

    The space is correct in that syntax. It compiles (I think my syntax is just wrong). But your second solution works perfectly. Thanks

    A little more analysis:

    This code works fine when creating a new linked table:

                .Fields.Append .CreateField("Website", dbMemo)

                .Fields("Email").Attributes = dbHyperlinkField

    Just not when adding a field to an existing table. I think the difference is when adding a new table, it isn't actually appended until all the fields and attributes are created and set.

    Anyway, thank you for your help.

    Was this answer helpful?

    0 comments No comments
  2. Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
    2015-10-02T03:21:09+00:00

    First off, there is a Space before ".Attributes"

    Was this answer helpful?

    0 comments No comments