Solved

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

Posted on 2004-10-07
14
1,299 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
  • 6
  • 4
  • 2
  • +1
14 Comments
 
LVL 8

Expert Comment

by:jb79uk
Comment Utility
Try putting a DoEvents after your DoCmd.Hourglass action.

JB
0
 

Author Comment

by:colin4
Comment Utility
Thanks for the quick reply JB.

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

Expert Comment

by:jb79uk
Comment Utility
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
 
LVL 6

Expert Comment

by:Plamodo
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 6

Expert Comment

by:Plamodo
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks!

That works perfectly.

I really appreciate all of your help.
0
 
LVL 11

Expert Comment

by:Jokra_the_Barbarian
Comment Utility
You're welcome. Glad to help!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now