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?
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?
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
- Place a Button control over the image.
- Set the button's Transparent property to Yes so it becomes invisible.
- 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.
Thanks June,
Yes, the command button overlay works fine.
The thumbnail images populate quite slowly when the form opens. Maybe it's how I set the control's property ControlSourceCode:Private Sub cmdImageOverlay_Click() DoCmd.OpenForm "frmPic", , , , , acDialog, PicLib & ImageName & ".jpg" End Sub
"=ImPath([ImageName])"
Code:Public Function ImPath(ImName As String) As String ImPath = PicLib & ImName & ".jpg" End Function
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.
Just add that any control that does not have a got focus event (such as an image control) cannot set the current record