p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

access thread: Holding down a command button


Message #1 by "Clive Astley" <clive.astley@k...> on Tue, 25 Jun 2002 18:06:16
I have a command button which runs a sub when clicked with the mouse. How 
can I arrange for the sub to run continuously if the button is held down 
with the mouse please?
Message #2 by "Carnley, Dave" <dcarnley@a...> on Tue, 25 Jun 2002 12:18:41 -0500
I'm not sure how, you could try using MouseUp and MouseDown events.  Maybe
set a form timer at the quickest rate, on mousedown set a flag that the
timer proc checks, on mouseup clear that flag?  I'm just guessing, trying to
give you an idea.  However I don't think that this is a very typical GUI
operation so to support it you might have to write a lot of code and that
time might be better spent on other features.  Just my opinion.

Maybe an easier way would be to use toggle switches to allow the user to
turn the function on and off?

Have Fun!
David


-----Original Message-----
From: Clive Astley [mailto:clive.astley@k...]
Sent: Tuesday, June 25, 2002 1:06 PM
To: Access
Subject: [access] Holding down a command button


I have a command button which runs a sub when clicked with the mouse. How 
can I arrange for the sub to run continuously if the button is held down 
with the mouse please?
Message #3 by "cdebiasio@t... on Tue, 25 Jun 2002 19:29:31 +0200 (CEST)
Hi!

Play with MouseDown and MouseUp events. Until the button is "down", the Mouse 
is also down. So, call the function from that even procedure. Stop calling the 
procedure as you release the button, or set a "bCall = False" in the MouseUp 
event and use it in the called process to exit. 

Remember it's not a *GREAT* user interface, though, since buttons USUALLY 
cannot be clicked continuously (MS Access actually implements a "user interface 
discrepancy" in this case, but we shouldn't!).

HTH,

   Claudio de Biasio
     Team 97 S.r.l.


Quoting Clive Astley <clive.astley@k...>:

> I have a command button which runs a sub when clicked with the mouse.
> How 
> can I arrange for the sub to run continuously if the button is held down
> 
> with the mouse please?
> 
Message #4 by "cdebiasio@t... on Tue, 25 Jun 2002 19:37:34 +0200 (CEST)
Me again!

Also! I was forgetting the most important thing. No matter how you call 
continuously the function, remember it must be a fully re-entrant procedure. 
You have to be sure it doesn't execute multiple times in the same "cycle". This 
is achieved setting a boolean flag this way:


Function Boo () As Buu

   Static bInProc As Boolean

   'Let's bail out if already executing proc.
   If (bInProc) Then Goto PROC_EXIT


   bInProc = True

      :
   'Your function body here
      :
    
   bInProc = False


PROC_EXIT:


End Function



Quoting "cdebiasio@t..." <cdebiasio@t...>:

> Hi!
> 
> Play with MouseDown and MouseUp events. Until the button is "down", the
> Mouse 
> is also down. So, call the function from that event procedure. Stop
> calling the 
> procedure as you release the button, or set a "bCall = False" in the
> MouseUp 
> event and use it in the called process to exit. 
> 
> Remember it's not a *GREAT* user interface, though, since buttons
> USUALLY 
> cannot be clicked continuously (MS Access actually implements a "user
> interface 
> discrepancy" in this case, but we shouldn't!).
> 
> HTH,
> 
>    Claudio de Biasio
>      Team 97 S.r.l.
> 
> 
> Quoting Clive Astley <clive.astley@k...>:
> 
> > I have a command button which runs a sub when clicked with the mouse.
> > How 
> > can I arrange for the sub to run continuously if the button is held
> down
> > 
> > with the mouse please?
> > 
> 
> 
Message #5 by "Leo Scott" <leoscott@c...> on Tue, 25 Jun 2002 11:20:54 -0700
Use something like the code below.  Make sure and set the form/module level
mblnKeepRunning to false in the Form_Load or Form_Activate event.

Private mblnKeepRunning As Boolean

Private Sub KeepRunning()
   Do While mblnKeepRunning
      'put your code here
   Loop
End Sub

Private Sub btnKeepRunning_MouseDown(Button As Integer, Shift As Integer, _
                                     X As Single, Y As Single)
   mblnKeepRunning = True
   Call KeepRunning
End Sub

Private Sub btnKeepRunning_MouseUp(Button As Integer, Shift As Integer, _
                                   X As Single, Y As Single)
   mblnKeepRunning = False
End Sub


|-----Original Message-----
|From: cdebiasio@t... [mailto:cdebiasio@t...]
|Sent: Tuesday, June 25, 2002 10:38 AM
|To: Access
|Subject: [access] Re: Holding down a command button
|
|
|Me again!
|
|Also! I was forgetting the most important thing. No matter how you call
|continuously the function, remember it must be a fully re-entrant
|procedure.
|You have to be sure it doesn't execute multiple times in the same
|"cycle". This
|is achieved setting a boolean flag this way:
|
|
|Function Boo () As Buu
|
|   Static bInProc As Boolean
|
|   'Let's bail out if already executing proc.
|   If (bInProc) Then Goto PROC_EXIT
|
|
|   bInProc = True
|
|      :
|   'Your function body here
|      :
|
|   bInProc = False
|
|
|PROC_EXIT:
|
|
|End Function
|
|
|
|Quoting "cdebiasio@t..." <cdebiasio@t...>:
|
|> Hi!
|>
|> Play with MouseDown and MouseUp events. Until the button is "down", the
|> Mouse
|> is also down. So, call the function from that event procedure. Stop
|> calling the
|> procedure as you release the button, or set a "bCall = False" in the
|> MouseUp
|> event and use it in the called process to exit.
|>
|> Remember it's not a *GREAT* user interface, though, since buttons
|> USUALLY
|> cannot be clicked continuously (MS Access actually implements a "user
|> interface
|> discrepancy" in this case, but we shouldn't!).
|>
|> HTH,
|>
|>    Claudio de Biasio
|>      Team 97 S.r.l.
|>
|>
|> Quoting Clive Astley <clive.astley@k...>:
|>
|> > I have a command button which runs a sub when clicked with the mouse.
|> > How
|> > can I arrange for the sub to run continuously if the button is held
|> down
|> >
|> > with the mouse please?
|> >
|>
|>
|

Message #6 by "Gregory Serrano" <SerranoG@m...> on Tue, 25 Jun 2002 22:16:36
Clive,

<< I have a command button which runs a sub when clicked with the mouse. 
How can I arrange for the sub to run continuously if the button is held 
down with the mouse please? >>

For this situation, I would not use a command button held down 
continuously.  I would use an option group (yes/no) with "Run" (option 1) 
and "Stop" (option 2) toggle buttons.  The "On Click" event code would 
look roughly like this:

   Do While Me.optRunCode = 1
      'Code that does stuff here.
   Loop

As noted by someone else, make sure you don't have any circular references 
in the code, e.g. Sub A calls Sub B that calls Sub A again which calls Sub 
B again, etc. ad nauseum.

Beware code that runs forever!  Windows tends to have memory allocation 
problems!

Greg
Message #7 by "Amy Wyatt" <amyw@c...> on Wed, 26 Jun 2002 13:54:41
This is excedingly difficult to accomplish if not impossible. You may just 
have to teach your users how to do a Ctrl+Break to interrupt a running 
function and then handle the problems of a break in the middle of the 
code. Otherwise you will either get into a continuous loop that will only 
end in an error or you will not accomplish what you are trying to do 
because it will end too soon.

I am curious, why would you want to do this?

Amy

> I have a command button which runs a sub when clicked with the mouse. 
How 
c> an I arrange for the sub to run continuously if the button is held down 
w> ith the mouse please?
Message #8 by "Clive Astley" <clive.astley@k...> on Wed, 26 Jun 2002 17:59:01
Many thanks to everybody for their help. The subject is not as easy as I 
originally thought - I just thought it was me being dense when I couldn't 
solve it.

Amy asks why I would want to do it. Well, when you press the keyboard key 
K then letter "K" is printed. If you hold the key down then you 
get "KKKKKKK" for as long as held down.

My button just nudges the values of some currency boxes by 1p when the 
button is pressed. If you need to nudge by 5p then it is 5 presses. But 
what about 50p or a 1. Gets a bit of a pain so the currency boxes get 
typed in rather than nudged. I thought it would be nice if the button 
could be held down and the nudge routine just repeats itself until the 
button is released.

Again, many thanks to all for your interest.

Clive
Message #9 by ProDev <prodevmg@y...> on Wed, 26 Jun 2002 10:00:12 -0700 (PDT)
--0-375216610-1025110812=:97828
Content-Type: text/plain; charset=us-ascii


 Why not have a text box on your form that allows you to put in the number of times it needs to be increased then run your procedure
enclosed in a For...Next loop the number of times in the box.
 
Just a thought...
 
 
  Clive Astley <clive.astley@k...> wrote: Many thanks to everybody for their help. The subject is not as
easy as I 
originally thought - I just thought it was me being dense when I couldn't 
solve it.

Amy asks why I would want to do it. Well, when you press the keyboard key 
K then letter "K" is printed. If you hold the key down then you 
get "KKKKKKK" for as long as held down.

My button just nudges the values of some currency boxes by 1p when the 
button is pressed. If you need to nudge by 5p then it is 5 presses. But 
what about 50p or a 1. Gets a bit of a pain so the currency boxes get 
typed in rather than nudged. I thought it would be nice if the button 
could be held down and the nudge routine just repeats itself until the 
button is released.

Again, many thanks to all for your interest.

Clive

Lonnie Johnson 
ProDev, Builders of MS Access Databases
http://www.galaxymall.com/software/PRODEV 




---------------------------------
Do You Yahoo!?
Sign-up for Video Highlights of 2002 FIFA World Cup
Message #10 by "Carnley, Dave" <dcarnley@a...> on Wed, 26 Jun 2002 12:02:43 -0500
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C21D33.496C7F20
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

what about the MS Forms 2.0 library Spin Button object.  little up and 
down
arrows that sit next to a field...



-----Original Message-----
From: ProDev [mailto:prodevmg@y...]
Sent: Wednesday, June 26, 2002 12:00 PM
To: Access
Subject: [access] Re: Holding down a command button



Why not have a text box on your form that allows you to put in the 
number of
times it needs to be increased then run your procedure enclosed in a
For...Next loop the number of times in the box.



Just a thought...




  Clive Astley <clive.astley@k...> wrote:


Many thanks to everybody for their help. The subject is not as easy as 
I
originally thought - I just thought it was me being dense when I 
couldn't
solve it.

Amy asks why I would want to do it. Well, when you press the keyboard 
key
K then letter "K" is printed. If you hold the key down then you
get "KKKKKKK" for as long as held down.

My button just nudges the values of some currency boxes by 1p when the
button is pressed. If you need to nudge by 5p then it is 5 presses. But 

what about 50p or a =A31. Gets a bit of a pain so the currency boxes 
get
typed in rather than nudged. I thought it would be nice if the button
could be held down and the nudge routine just repeats itself until the
button is released.

Again, many thanks to all for your interest.

Clive



Lonnie Johnson
ProDev, Builders of MS Access Databases
http://www.galaxymall.com/software/PRODEV
<http://www.galaxymall.com/software/PRODEV>






  _____ 

Do You Yahoo!?
Sign-up
<http://rd.yahoo.com/welcome/*http://fifaworldcup.yahoo.com/fc/en/spl> 
for
Video Highlights of 2002 FIFA World Cup --- 
http://p2p.wrox.com/manager.asp or 


Message #11 by "John Ruff" <papparuff@c...> on Wed, 26 Jun 2002 10:29:01 -0700
Clive,

To increment or decrement a value in a textbox, use the textbox's
KeyDown event.  Here is an example of incrementing a Date field up 1 day
and down 1 day. I'm using the Northwind Orders table.  The OrderDate is
the OrderDate field of the table.  This code can be modified for your
currency field.

Private Sub OrderDate_KeyDown(KeyCode As Integer, Shift As Integer)

    Select Case Shift
        Case 0  ' Make sure the Ctrl and Alt keys _
                    are not being pressed
        Select Case KeyCode
            Case 38 ' Down Arrow Key
                OrderDate = DateAdd("d", -1, OrderDate)
                KeyCode = 0
            Case 40 ' Up Arrow Key
                OrderDate = DateAdd("d", 1, OrderDate)
                KeyCode = 0
       End Select
    End Select

End Sub


John V. Ruff - The Eternal Optimist :-)
Always Looking for Contract Opportunities

www.noclassroom.com

Home:  xxx.xxx.xxxx
Cell:  xxx.xxx.xxxx
9306 Farwest Dr SW
Lakewood, WA 98498 
 
"Commit to the Lord whatever you do,
    and your plans will succeed."  Proverbs 16:3


-----Original Message-----
From: Clive Astley [mailto:clive.astley@k...] 
Sent: Tuesday, June 25, 2002 6:06 PM
To: Access
Subject: [access] Holding down a command button


I have a command button which runs a sub when clicked with the mouse.
How 
can I arrange for the sub to run continuously if the button is held down

with the mouse please?

Message #12 by "Leo Scott" <leoscott@c...> on Wed, 26 Jun 2002 11:01:26 -0700
This is a multi-part message in MIME format.

------=_NextPart_000_0010_01C21D00.D137DD60
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

I would strongly agree with this point.  The point of a common user interface, ie Windows, is to provide the user with
controls/objects that react the same way no matter what application you are running.  A command button does not commonly
fire confinuously when you hold it clicked.  A spin button does.  Stick with standards, your users will love you for it.
  -----Original Message-----
  From: Carnley, Dave [mailto:dcarnley@a...]
  Sent: Wednesday, June 26, 2002 10:03 AM
  To: Access
  Subject: [access] Re: Holding down a command button


  what about the MS Forms 2.0 library Spin Button object.  little up and down arrows that sit next to a field...


Message #13 by "Clive Astley" <clive.astley@k...> on Fri, 28 Jun 2002 08:00:18
Thanks John (KeyDown)and Leo (SpinButton). One of these will serve my 
purpose.

  Return to Index