Solved

Unable to display Hourglass from VBA code attached to the On-Click event of a label.

Posted on 2004-10-07
14
1,406 Views
Last Modified: 2008-01-09
Rather than using the MS Access button control object with its property limitations, I'm using a label object to mimic a button on my form.

Unlike the built-in button control, that always displays an Hourglass until the On-Click event is finished, I'm unable to get the On-Click event to display the Hourglass for my button created from a Label object.

I've tried using the DoCmd.Hourglass (True) and DoCmd.Hourglass (False) as well as the Screen.MousePointer = 11 and Screen.MousePointer = 1 on either side of the DoCmd.OpenForm event, but the Hourglass appears "after" the target form has opened, defeating the purpose.

Here is a sample of the code:

-----------------------------------------------------------------------------------
Private Sub btnBuild_Date_Click()

On Error GoTo btnBuild_Date_Click_Err

    DoCmd.OpenForm "frmBUILD_DATE", acNormal, "", "", , acNormal

btnBuild_Date_Click_Exit:
    Exit Sub

btnBuild_Date_Click_Err:
    MsgBox Error$
    Resume btnBuild_Date_Click_Exit

End Sub
-----------------------------------------------------------------------------------

There must be some way of getting the Hourglass to appear at the moment the label object is clicked.

I'd appreciate any help you could provide.
0
Comment
Question by:colin4
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
  • +1
14 Comments
 
LVL 8

Expert Comment

by:James Bendall
ID: 12252699
Try putting a DoEvents after your DoCmd.Hourglass action.

JB
0
 

Author Comment

by:colin4
ID: 12252796
Thanks for the quick reply JB.

I've already tried DoEvents, DoCmd.RepaintObject and Me.Repaint.
0
 
LVL 8

Expert Comment

by:James Bendall
ID: 12252945
No problem.  I see what you mean.  This does seem to be specific to the label control.

The next step (which I haven't tried yet) would be to try using API calls (CreateCursor, LoadCursor etc) but this seems a bit heavyweight (it will change the cursor for the whole Windows environment rather than just your app) for what you want - and there's no guarantee it will work.

JB
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 6

Expert Comment

by:Plamodo
ID: 12253018
So, you've tried it like this?  Do you have a 'docmd.hourglass false' in the load event of the form you're opening?

Private Sub btnBuild_Date_Click()
  docmd.hourglass true
  doevents
On Error GoTo btnBuild_Date_Click_Err

    DoCmd.OpenForm "frmBUILD_DATE", acNormal, "", "", , acNormal

btnBuild_Date_Click_Exit:
    Exit Sub

btnBuild_Date_Click_Err:
    MsgBox Error$
    Resume btnBuild_Date_Click_Exit

End Sub
0
 

Author Comment

by:colin4
ID: 12253248
Thanks, again, JB.

Yes, I put the DoCmd.Hourglass True and DoEvents in the same place you show them in your example - still no luck - the Hourglass appears "after" the new form opens and won't go away unless I manually issue DoCmd.Hourglass False from the immediate window.

And, Yes, I tried adding the DoCmd.Hourglass False to the Load event of the target form - when the form opens the pointer displays an arrow.  I guess the Load event is turning off the Hourglass before it can be displayed from the initial code.
0
 
LVL 11

Expert Comment

by:Jokra_the_Barbarian
ID: 12253800
Colin,this should work...

Private Sub Label1_Click()
    TimerInterval = 10
End Sub

Private Sub Form_Timer()
        DoCmd.Hourglass True
        DoCmd.OpenForm "form1"
        DoCmd.Hourglass False
        TimerInterval = 0
End Sub

0
 

Author Comment

by:colin4
ID: 12254153
Thanks for the code sample.

However, I don't see the entry point for the second Form_Timer sub procedure.  Is it called from another line?

I must have missed something.
0
 
LVL 6

Expert Comment

by:Plamodo
ID: 12254196
if you set me.timerinterval to a value greater than zero, the form's timer event trips every time the specified time interval elapses.
0
 

Author Comment

by:colin4
ID: 12254375
Thanks for the suggestion.

I'm a novice, and really don't see where the code sample you provided fits into my original code sample.

My On-Click event is a single sub procedure in the source form that opens a target form.

I'd appreciate it if you could modify the code below to show me how it works:

==========================

Private Sub btnBuild_Date_Click()

On Error GoTo btnBuild_Date_Click_Err

    DoCmd.OpenForm "frmBUILD_DATE", acNormal, "", "", , acNormal

btnBuild_Date_Click_Exit:
    Exit Sub

btnBuild_Date_Click_Err:
    MsgBox Error$
    Resume btnBuild_Date_Click_Exit

End Sub



0
 
LVL 11

Expert Comment

by:Jokra_the_Barbarian
ID: 12254407
So, the code that you would need to add/modify is...

Private Sub Form_Timer()
        DoCmd.Hourglass True
        DoCmd.OpenForm "frmBUILD_DATE", acNormal, "", "", , acNormal
        DoCmd.Hourglass False
        TimerInterval = 0
End Sub

Private Sub btnBuild_Date_Click()
   On Error GoTo btnBuild_Date_Click_Err

   TimerInterval = 10

   btnBuild_Date_Click_Exit:
       Exit Sub

   btnBuild_Date_Click_Err:
       MsgBox Error$
       Resume btnBuild_Date_Click_Exit
End Sub
0
 

Author Comment

by:colin4
ID: 12254498
Thanks for your patience and support.

I really appreciate your time.

The example you provided works great for 1 of the 10 buttons on the form, but now how do I use the same Form_Timer for the other 9 buttons that point to different target forms ?
0
 
LVL 11

Accepted Solution

by:
Jokra_the_Barbarian earned 125 total points
ID: 12254566
You could dim a variable for the form module (at top under Option Compare Database):
  Option Compare Database
  Dim frmName As String
------------------------------------

In your label click event:
  frmName = "frmBUILD_DATE"    
  TimerInterval = 10

In the form timer event:
  DoCmd.OpenForm frmName, acNormal, "", "", , acNormal

Once the timer event is defined, all you have to do is add 2 lines for each label click event.
0
 

Author Comment

by:colin4
ID: 12259026
Thanks!

That works perfectly.

I really appreciate all of your help.
0
 
LVL 11

Expert Comment

by:Jokra_the_Barbarian
ID: 12259555
You're welcome. Glad to help!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question