Solved

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

Posted on 2004-10-07
14
1,312 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
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
 
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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…

867 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

12 Experts available now in Live!

Get 1:1 Help Now