Double click image in data sheet -- go to current record (1 Viewer)

CedarTree

Registered User.
Local time
Today, 00:51
Joined
Mar 2, 2018
Messages
404
I have a datasheet subform (not sure that matters for my question) where each record has an image field. I added a double-click event so when you dbl-click on the image, it opens it in MS image viewer. If I'm "on" record 1 and I double click the image on that row, works great. If I dbl-click on the image in record 2, it still opens image 1 b/c it things I"m still on record 1. I have to select the next record then dbl-click for it to work. When I dbl-click, I'd like VBA to recognize I'm now on a different record. Thoughts? Thanks!
 

CedarTree

Registered User.
Local time
Today, 00:51
Joined
Mar 2, 2018
Messages
404
By the way, the image control source is set equal to a filename which is the image residing on the LAN.
 

nhorton79

Registered User.
Local time
Today, 16:51
Joined
Aug 17, 2015
Messages
147
Is the double click event on the subform? If so, it will only work on the selected record.

I’m away from computer at the moment so can’t tell, but if there is a double click event on the actual field in the datasheet form then add the code to that event rather than the subform double click event.


Sent from my iPhone using Tapatalk
 

CedarTree

Registered User.
Local time
Today, 00:51
Joined
Mar 2, 2018
Messages
404
Subform and detail sections have double-click events but then double-clicking on the image itself doesn't seem to trigger the event if I go that route.
 

nhorton79

Registered User.
Local time
Today, 16:51
Joined
Aug 17, 2015
Messages
147
You don't want to put the code on the subform event.

You want to put this code on the field double click event on your actual subform.
Which in your case would be your image field.

See my IMG1.jpg file, showing in Design View.

Then the IMG2.jpg file contains what the form looks like in Form View.

My code on the double click event was:

Code:
Private Sub Attachment_Click()
    MsgBox "" & Me.Attachment
End Sub

This just showed (in a message box) the path of the attachment of whatever row I double-clicked on, but you would replace that with whatever code you have.

Hopefully this helps.
 

Attachments

  • IMG1.jpg
    IMG1.jpg
    101 KB · Views: 43
  • IMG2.jpg
    IMG2.jpg
    92.3 KB · Views: 38

CedarTree

Registered User.
Local time
Today, 00:51
Joined
Mar 2, 2018
Messages
404
Sorry this doesn't solve the original issue. I had it connected to the field event. The problem is that double clicking on an image in Record 2 doesn't change the current record to Record 2.
 

nhorton79

Registered User.
Local time
Today, 16:51
Joined
Aug 17, 2015
Messages
147
Are you able to post the code you are using on the double click event?
Everything including the Private Sub / End Sub pieces?
Possibly even a screenshot showing the form/subform.

Might just help me picture exactly what you’re trying to do and replicate it


Sent from my iPhone using Tapatalk
 

CedarTree

Registered User.
Local time
Today, 00:51
Joined
Mar 2, 2018
Messages
404
Here's the code...

Code:
Private Sub imgCheckBox_DblClick(Cancel As Integer)

    Dim sCheckBoxPath As String, sCheckBoxFile As String
    Dim sFullFileName As String
    
    Me.imgCheckBox.Requery
    sCheckBoxPath = fnCheckNullString(Me.CheckBoxImagePath)
    sCheckBoxFile = fnCheckNullString(Me.CheckBoxImageFile)
    If sCheckBoxPath = "" Or sCheckBoxFile = "" Then Exit Sub
    sFullFileName = fnCheckBoxFileName(sCheckBoxPath, sCheckBoxFile) 'THIS JUST CREATES A PATH + FILENAME
    If sFullFileName <> "" Then
        Shell "RunDLL32.exe C:\Windows\System32\Shimgvw.dll,ImageView_Fullscreen " & sFullFileName
    End If
    
End Sub
 
Last edited:

CedarTree

Registered User.
Local time
Today, 00:51
Joined
Mar 2, 2018
Messages
404
Here's a snip...


  • So if I double-click (DC) on first image, it works
  • If I select the 2nd record then DC on 2nd image it works
  • If I've selected 2nd record then DC on 1st image or 3rd image, it opens the 2nd image
 

Attachments

  • CheckBox.JPG
    CheckBox.JPG
    16.8 KB · Views: 162

Mark_

Longboard on the internet
Local time
Yesterday, 21:51
Joined
Sep 12, 2017
Messages
2,111
Can you use continuous form view instead of datasheet?

ACCESS acts differently on a continuous form from on a datasheet.
 

nhorton79

Registered User.
Local time
Today, 16:51
Joined
Aug 17, 2015
Messages
147
That looks like a continuous form anyway....
Its doesn't look like a datasheet to me although I could be mistaken.
Stacked headers and fields, with conditional formatting and images...seems like its a continuous form.

I've recreated this and have the same issue.

The reason is that even when you click an image on a continuous form, it doesn't give that record focus.
This is supposedly a known issue in Access.

After a little research, there is a workaround that I discovered on another website, which involves putting a transparent button over the image which gets focus on clicking. You then use that buttons onclick, doubleclick event

Link to website:
https://www.devhut.net/2013/10/27/m...m-not-returning-the-proper-recordprimary-key/

Also, see my attached database, where I have replicated something similar.
Just change some of the image links if they don't show on your end.
 

Attachments

  • Test.accdb
    468 KB · Views: 37

nhorton79

Registered User.
Local time
Today, 16:51
Joined
Aug 17, 2015
Messages
147
Hi Cedartree,
Just wondering whether that resolved your issue?


Sent from my iPhone using Tapatalk
 

CedarTree

Registered User.
Local time
Today, 00:51
Joined
Mar 2, 2018
Messages
404
Thanks for suggestion. I'll try it and let you know (if I can remember to!)
 

nhorton79

Registered User.
Local time
Today, 16:51
Joined
Aug 17, 2015
Messages
147
No problem.
I’ve received so much assistance on this forum over the years so just happy I could help someone else out.


Nick
Sent from my iPhone using Tapatalk
 

Users who are viewing this thread

Top Bottom