We help IT Professionals succeed at work.

Hourglass not working when used in Image Onclick event in Access 2007

BradleyCleveland
BradleyCleveland used Ask the Experts™
on
I'm using Access 2007. I don't know if the problem exists in other versions or not.  When initiating the Hourglass command on a command button, the cursor changes to an hourglass like it is supposed to. When initiating the same code on the OnClick event of an image, the cursor does not change to an hourglass.  As an example, paste the following lines of code behind the Onclick command of a command button, and paste the code behind the onclick event of the image and then compare the results.  Anybody have a solution to this?

Dim dt As Date
DoCmd.Hourglass True
dt = DateAdd("s", 6, Now())
Do Until dt < Now
    DoEvents
Loop
DoCmd.Hourglass False
MsgBox "Finished"
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
make your button transparent and put it over your picture
by the way after you move your transparent button over your picture - in design view right click on your button and chose  position  bring to front.

i am unable to work with access right now to see if there is a better answer.

another thing you can do is check to see if your picture is enabled = true
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
I was able to reproduce the problem. And the reason is ... the Click event was not occurring because, the Default setting for an image when you first put it onto a form for Enabled and Locked is
Enabled = No
Locked = Yes

So ... no event is triggered.

Change to
Enabled = Yes
Locked = No

and it works.

mx
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
opps ... however, there is still no hourglass!  Not sure why.

I also used an image control ... no hourglass.  Although, the was already enabled as the default.

mx
I just tried in Access 2003 and observed the same thing. It's not a problem with screen refresh (this would have been handled by DoEvents anyway) because setting Me.Caption to something at the top of the handler is immediately visible.

On the other hand, when stepping through the code, the hourglass works, but the VB Editor is active at that time. I can only guess that images have a different mouse handling scheme than regular controls: the same happens for both image controls and unbound object frames.

Use conagraman's suggestion or place the image directly in the button (if you want that sort of look). I did not find a way to make the hourglass appear, even by changing the focus and other similar tricks, but I haven't tried WinAPI calls — I'm sure it's possible if you really need it.

(°v°)

Author

Commented:
I've got this problem resolved by using an API call as harfang suggested. Here is a link to another posting using API

http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_21506102.html?sfQueryTermInfo=1+10+30+sethourglass+true
Thanks for the points, grade, and especially the feedback. I was away for a couple of weeks and I'm glad you found a working example. — (°v°)