Hyperlink removal with VBA? (1 Viewer)

mactreb

Registered User.
Local time
Today, 15:48
Joined
Jan 15, 2017
Messages
13
Hi all,

I have a form with a textbox linked to a hyperlink field which is used to ingest PDF files into a database (you drag the PDF on to the textbox, it copies the file from the link location to another specified location, renaming the file along the way).

That works fine for a new record. But where you're trying to add it to an existing record it doesn't: you can't drag the PDF on to the textbox. This seems to be because access already thinks there's a hyperlink there (even if the field actually empty and you've never added a link to it). To solve the problem, you need to right click on the textbox --> hyperlink --> remove hyperlink.

Is there a way to do that with VBA on (say) the form load event? It doesn't matter if it clears the hyperlink data from the record - that's never actually used (and indeed, the field only exists to allow this operation).

Cheers
 

Eljefegeneo

Still trying to learn
Local time
Today, 07:48
Joined
Jan 10, 2011
Messages
904
Well I may be completely wrong on this, but I always have had problems editing hyperlink fields. So I do not use them. Instead I make the field a text field and then use code to go to the link. For example, for my web page field on a form I use the following:

Code:
Private Sub WebPage_DblClick(Cancel As Integer)
'WebPage is no longer a hyperlink, this code will bring up the web page
Dim WebLink As String
    If Me.WebPage Like "http://" & "*" Then
        WebLink = Me.WebPage
Else
    WebLink = "http://" & Me.WebPage
End If
 
        Application.FollowHyperlink WebLink, , True
End Sub
Then editing the field is a piece of cake.
 

mactreb

Registered User.
Local time
Today, 15:48
Joined
Jan 15, 2017
Messages
13
Thanks.

The problems is that - as far as I can tell - you must use a hyperlink field to have the pseudo drag-and-drop functionality. You can't drop a file onto a text control unless that control's source is a hyperlink field.

I'm not fussed with following the link (the after change event for the control is a filecopy, which just copies the 'dropped' file to a defined location, then hides he control - after that I've no need for the data in the field).
 

Eljefegeneo

Still trying to learn
Local time
Today, 07:48
Joined
Jan 10, 2011
Messages
904
Sorry, that I cannot help you with. But why not just copy and paste. Just as good as drag and drop.
 

Beetle

Duly Registered Boozer
Local time
Today, 08:48
Joined
Apr 30, 2011
Messages
1,808
You might try the following code line, keep in mind that you need to make sure the text box has focus first;

Me!YourTextBox.SetFocus
DoCmd.RunCommand acCmdClearHyperlink
 

mactreb

Registered User.
Local time
Today, 15:48
Joined
Jan 15, 2017
Messages
13
Beetle, that worked perfectly - thanks. (Though, weirdly, it only appears to work as it should in runtime)
 

Users who are viewing this thread

Top Bottom