Home  |   French  |   About  |   Search  | mvps.org  

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

In Memoriam

Terms of Use


VB Petition

Tables: Create Hyperlink Field from code

Author(s)
Dev Ashish

(Q)    I'm unable to create a Hyperlink Field in a table from code.   What are the steps that I need to take or is this possible?

(A)    To create a Hyperlink field, you need to set the Attributes to dbHyperlinkField. 

    Try this function as an example.

'****************** Code Start *******************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
'
Function fTableWithHyperlink(stTablename As String) As Boolean
   On Local Error GoTo fTableWithHyperlink_Err
Dim Msg As String ' for error handling
Dim db As Database
Dim tdf As TableDef
Dim fld As Field
    Set db = CurrentDb
    Set tdf = db.CreateTableDef(stTablename)
    Set fld = tdf.CreateField("HyperlinkTest", dbMemo)
    fld.Attributes = dbHyperlinkField
    tdf.Fields.Append fld
    tdf.Fields.Refresh
    db.TableDefs.Append tdf
    db.TableDefs.Refresh
    Set fld = Nothing
    Set tdf = Nothing
    Set db = Nothing
   
    fTableWithHyperlink = True

fTableWithHyperlink_End:
   Exit Function

fTableWithHyperlink_Err:
   fTableWithHyperlink = False
   Msg = "Error Information..." & vbCrLf & vbCrLf
   Msg = Msg & "Function: fTableWithHyperlink" & vbCrLf
   Msg = Msg & "Description: " & Err.Description & vbCrLf
   Msg = Msg & "Error #: " & Format$(Err.Number) & vbCrLf
   MsgBox Msg, vbInformation, "fTableWithHyperlink"
   Resume fTableWithHyperlink_End
End Function
'****************** Code End *******************

© 1998-2010, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer