Solved

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

Posted on 2004-10-07
14
1,373 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:jb79uk
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:jb79uk
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

730 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