none
Updating Hyperlink Addresses in VBA (MS Access)

    Question

  • Hi,

    I am making a database which uses labels to link to external files. I have the path of the file defined in a table and there is a test box on the form that displays it also. On the form load event the hyperlink address is set to whatever is in that text box:



    Me.txtgroundFloorPlan100.Visible = True
    Me.txtgroundFloorPlan100.SetFocus
    groundFloorPlan100 = Me.txtgroundFloorPlan100.Text
    Me.cmdRefresh.SetFocus
    Me.txtgroundFloorPlan100.Visible = False
    Me.lblgroundFloorPlan100.HyperlinkAddress = groundFloorPlan100
    If Me.lblgroundFloorPlan100.HyperlinkAddress = "" Then
    Me.lblgroundFloorPlan100.ForeColor = RGB(204, 204, 204)
    Me.lblgroundFloorPlan100.ControlTipText = "Drawing Unavailble"
    Else
    Me.lblgroundFloorPlan100.ForeColor = RGB(0, 0, 255)
    Me.lblgroundFloorPlan100.FontUnderline = True
    Me.lblgroundFloorPlan100.ControlTipText = "Click to open drawing"
    End If

     

    I have added navigation buttons onto the form and have added this code to them also:


    Me.txtgroundFloorPlan100.Visible = True
    Me.txtgroundFloorPlan100.SetFocus
    groundFloorPlan100 = Me.txtgroundFloorPlan100.Text
    Me.cmdRefresh.SetFocus
    Me.txtgroundFloorPlan100.Visible = False
    Me.lblgroundFloorPlan100.HyperlinkAddress = ""
    Me.lblgroundFloorPlan100.HyperlinkAddress = groundFloorPlan100
    If Me.lblgroundFloorPlan100.HyperlinkAddress = "" Then
    Me.lblgroundFloorPlan100.ForeColor = RGB(204, 204, 204)
    Me.lblgroundFloorPlan100.ControlTipText = "Drawing Unavailble"
    Else
    Me.lblgroundFloorPlan100.ForeColor = RGB(0, 0, 255)
    Me.lblgroundFloorPlan100.FontUnderline = True
    Me.lblgroundFloorPlan100.ControlTipText = "Click to open drawing"
    End If

     

    The problem is that the Hyperlink address doesn’t update, it links to the path in the first record.

    Can anybody help?

    Thanks

    Lewis

    Tuesday, October 25, 2005 9:43 AM

Answers

  • Hi Lewis,

    Here's the response I got from one of our support engineers:

    I suppose our buddy build the form with Access form wizard. The Onload event will be fired only once during the form rendering. I suppose it’s the reason why the caption never changes on data navigating. You can try following step to fix this issue:

    1.       Create a form and bound the data to the controls. By default, the Hyperlink type fields will be bound to a textbox.

    2.       Set the Visible property of the textbox and related label to ‘False’

    3.       Add a new label and cover the textbox

    4.       Add code to Form_Current event

     

    Private Sub Form_Current()

        If Me.HyperLink.Value <> "" Then

            Me.lbHyperLink.Caption = Me.HyperLink.Value

            ……

        End If

    End Sub

          For detail information of OnCurrent Event, please refer to: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac10/html/acproOnCurrent.asp



    thanks,
    -brenda

    Monday, November 07, 2005 8:32 PM