Results 1 to 5 of 5
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,095

    control OnClick event to make record the current record

    On a continuous form, click one of the bound fields to effectively be the same as though having clicked on the record selector. I want to click on an image control and have the detected row become the current record.

    How do I do that in code?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Bing Search: "access vba click on image control and set focus on record"

    CoPilot Response:

    In Microsoft Access VBA, an Image control does not inherently support setting focus to a record because it is not part of the tab order or focusable elements. However, you can work around this limitation by using a transparent button over the image or by handling the click event of the image to programmatically set focus to the desired record.

    Option 1: Use a Transparent Button Over the Image

    1. Place a Button control over the image.
    2. Set the button's Transparent property to Yes so it becomes invisible.
    3. Use the button's OnClick event to set focus to the desired record.

    Code:
    Private Sub TransparentButton_Click()
        Me.RecordSelectorControl.SetFocus ' Replace with the control bound to the record
    End Sub

    Option 2: Handle the Image's Click Event

    If you prefer to use the image's OnClick event directly, you can write VBA code to set focus to a specific control in the current record.[/COLOR
    Code:
    Private Sub ImageControl_Click()
        Me.RecordSelectorControl.SetFocus ' Replace with the control bound to the record
    End Sub

    Option 3: For Continuous Forms

    If you are working with a Continuous Form, you need to ensure the correct record is selected. You can use the Bookmark property of the form to navigate to the desired record.
    Code:
    Private Sub ImageControl_Click()
        Dim rs As DAO.Recordset
        Set rs = Me.RecordsetClone
    
        ' Navigate to the current record
        rs.Bookmark = Me.Bookmark
        Me.RecordSelectorControl.SetFocus ' Replace with the control bound to the record
    End Sub



    Probably Option 1 is what you want. Clicking button sets focus on record. What else should happen?
    Last edited by June7; 09-28-2025 at 05:26 AM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,095
    Thanks June,
    Yes, the command button overlay works fine.
    Code:
    Private Sub cmdImageOverlay_Click()
    DoCmd.OpenForm "frmPic", , , , , acDialog, PicLib & ImageName & ".jpg"
    End Sub
    The thumbnail images populate quite slowly when the form opens. Maybe it's how I set the control's property ControlSource
    "=ImPath([ImageName])"

    Code:
    Public Function ImPath(ImName As String) As String
    ImPath = PicLib & ImName & ".jpg"
    End Function

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Not sure images can load faster. How large are images?
    Where does PicLib come from? Is this a global variable?
    ControlSource cannot directly reference a global variable but it can a TempVar.
    Global variable will lose value if code execution is interrupted by an unhandled run-time error. TempVar does not.
    Last edited by June7; 09-28-2025 at 12:51 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    Just add that any control that does not have a got focus event (such as an image control) cannot set the current record

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 11-11-2021, 02:09 AM
  2. Replies: 6
    Last Post: 06-04-2018, 06:46 AM
  3. OLEunbound onclick event
    By thangasiva in forum Forms
    Replies: 1
    Last Post: 03-26-2015, 10:55 AM
  4. OLEunbound onclick event
    By thangasiva in forum Access
    Replies: 1
    Last Post: 06-27-2010, 01:49 PM
  5. OnClick event
    By HotTomales in forum Forms
    Replies: 1
    Last Post: 12-24-2009, 08:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums