Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

vba - Loading an image makes listbox & textboxes blink once

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:pathfilename.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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:
="\servernamepathImages" & [listbox name]


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...