2

In Access 2016 I have a form with a listbox, and an img Image Control named imgFrame.

When a filename is clicked in the listbox, the image is displayed. The code for the listbox's Click event is: imgFrame.Picture = "c:\path\filename.jpg"

Any time this line runs, the image loads but the Image Control (and any text boxes on the form) blink once. (The command button does not blink.)


Screenshot (in slow-mo)

img

I tried padding with Application.Echo like this:

Sub showImg_pic(fName)
    Application.Echo False
    imgFrame.Picture = fName
    DoEvents
    Application.Echo True
End Sub

and experimented with imgFrame.Visible in the same way but saw no difference.

Community
  • 1
  • 1
ashleedawg
  • 20,365
  • 9
  • 72
  • 105
  • Uh oh, not as quick as I thought... i should have also mentioned I'm open to suggestions for better controls than this one. I haven't worked with image controls very much. – ashleedawg May 07 '18 at 07:09
  • What do you mean with _I tried `Application.Echo False`? This is normally fixed by using `Application.Echo False`, then your code, then possibly a `DoEvents`, and then `Application.Echo True`. As for image controls, I tend to use the web browser control with a whole lot of VBA, also because it allows me to load images from the database without storing them on-disk. – Erik A May 07 '18 at 07:27
  • @Erik - I doubled-checked (code above) and it made no difference. As for the web control, these photos need to remain stored on disk. I tried and the only problem I can see is that the image doesn't auto-resize to the control size like the picture control. Is there a "whole lot of VBA just to do that? – ashleedawg May 07 '18 at 14:03
  • Nope, the VBA is mostly converting the binary data into base64 so I can load the image without storing it on disk. You can use a simple bit of HTML to auto-resize the image: ``. A more full variant of what I use can be found [here](https://stackoverflow.com/a/46793834/7296893) – Erik A May 07 '18 at 14:06

1 Answers1

2

Code setting Picture property was required back with Access 2003 before ControlSource property was added to the Image control.

I have never used the Picture property. I use ControlSource property to dynamically load images in Image control. It can reference an attachment type field that holds image files but embedding files can substantially increase db size, more quickly reaching 2GB Access file size limit. So, can also reference a text field that has full image path for external location, or partial path and use an expression to construct full path. No VBA code. No blinking.

="C:\your folder path\" & [listbox name]

Use any field to construct image filename:
="C:\your folder path\" & [EmployeeID] & ".jpg"

If the images are in a folder next to the db:
=CurrentProject.Path & "\Images\" & [listbox name]

If the images are in central server location, use UNC path:
="\\servername\path\Images\" & [listbox name]

June7
  • 19,874
  • 8
  • 24
  • 34