We’d like to remind Forumites to please avoid political debate on the Forum.

This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.

📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!

Help with Application.FollowHyperlink in Access

_Andy_
_Andy_ Posts: 11,150 Forumite
Hi

I'm trying to have a button on a form which then opens a PDF file.
I have made a text field (Test) which has the full path on a shared drive to the PDF.

I've tried

Application.FollowHyperlink Test

But the button doesn't do anything.
If I change it to

Application.FollowHyperlink "Thepathname"

It opens the file, so it can't be the path/file name being wrong in the actual data.

Any ideas?
Thanks

PS Using Access 2003

Comments

  • _Andy_
    _Andy_ Posts: 11,150 Forumite
    Should have put - it doesn't do 'nothing' - it opens up an address bar (with the database location filled in) for some reason.
  • _Andy_
    _Andy_ Posts: 11,150 Forumite
    *bump* - still haven't been able to fix it.
  • hotkee
    hotkee Posts: 505 Forumite
    Am not an expert on Access - have phaffed with it a litte from time to time .

    Have you got the latest acrobat?

    Is the pdf in the same location as the access file?

    It might be invoking acrobat and closing it without you noticing?
  • RobTang
    RobTang Posts: 1,064 Forumite
    try

    [TextBoxObject].SetFocus
    Application.FollowHyperlink ([TextBoxObject].Text)

    ie

    Form_Form1.Textbox0.SetFocus
    Application.FollowHyperlink(Form_Form1.Textbox0.Text)

    Works on Access 07, usual stuff like macros must be enabled etc.
  • _Andy_
    _Andy_ Posts: 11,150 Forumite
    Rob

    Not sure if I'm doing this right but I'm getting runtime errors

    I've put

    "Private Sub Command83_Click()
    Form_Form1.Command83.SetFocus
    Application.FollowHyperlink (Form_Form1.Command83.test2)
    End Sub"

    On a command button, i.e. command83 is the name of the button

    test2 is the name of the field that holds the file path and name. I used right click > build event > code builder.

    It's highlighting "Form_Form1.Command83.SetFocus" line as being wrong?

    Thanks
  • _Andy_
    _Andy_ Posts: 11,150 Forumite
    Also tried

    Application.FollowHyperlink Me.Test2

    Which would be nice and simple but I get
    "Compile error:
    Method or data member not found"
  • _Andy_
    _Andy_ Posts: 11,150 Forumite
    Fixed - I used

    Private Sub Command84_Click()
    Dim TestStr As String
    TestStr = [FieldName]
    Application.FollowHyperlink TestStr, , True, True
    End Sub

    Works very nicely :)
  • RobTang
    RobTang Posts: 1,064 Forumite
    for various reasons which im not quite sure about, if you want to access a member of an object on a form it needs to have focus.

    (im going to assume the field is populated into a textbox object)
    so you'll need to do

    me.Test2.SetFocus 'This gives the field focus and will allow you access the value of the field
    Application.FollowHyperlink (me.Test2.Text) ' gives the VALUE of Test2 to the function

    You can't do Me.Test2 because its just an object you need to access on of its members (in this case .text) to get any info or functionality from it.
This discussion has been closed.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 352.2K Banking & Borrowing
  • 253.6K Reduce Debt & Boost Income
  • 454.3K Spending & Discounts
  • 245.2K Work, Benefits & Business
  • 600.9K Mortgages, Homes & Bills
  • 177.5K Life & Family
  • 259K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16K Discuss & Feedback
  • 37.7K Read-Only Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.