Solved

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

Posted on 2004-10-07
14
1,320 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

815 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

10 Experts available now in Live!

Get 1:1 Help Now