ms-accessonclickvbarecord

Access 2010 Forms VBA - Set Focus to Record on image click


I have a Form 'frm_doc_revs' that has a control source set to a query I made: 'query_doc_form'. I set this form with "Default View" property to "Continuous Forms" Everything is working as expected EXCEPT

When I click on an image in a record I have an "On-Click" method that creates a hyperlink to a file and opens the path - The problem is that I must first set focus to the record, THEN click on the image in order to get the correct path. If I just click the image, it does not place focus on the record

---> What I need is VBA code such that when the user clicks on an image in a record, the code places focus on that record first <---

I'm at a loss here - any advice will be greatly appreciated.

Here's an image describing the situation a little better - My simple Click Methods are below

enter image description here

VBA CODE

Private Sub pdf_img_Click()
   Dim fname As String, fpath As String

   fname = Me.PDF_NAME
   fpath = "P:\Engineering\002 Engineering Data Base\Design Standards Database\pdf\" & fname

   MsgBox (fpath)
   'Application.FollowHyperlink (fpath)

End Sub

Solution

  • Yes, images don't set the focus to the record.

    Easiest method: use a button instead, which has the image as Picture property.

    If you don't like the look of that, create a transparent button (set the Transparent property to Yes) with the same dimensions as the image, and put it in front of the image.

    Then move your code in the OnClick event procedure of the button.