Check the MouseDown Shift status from a function

  • Follow


Hi All

I am playing around with a form with 280 unbound controls (7 days x 40
time slots per day).  I'd like to be able to check the Shift status on
each of these controls during the MouseDown event.  I can use the
MouseDown event procedure:

Private Sub Day101_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
If Shift = 1 Then
    booShiftDown = True
Else
    booShiftDown = False
End If
End Sub

but I'd have to copy this for each unbound control and modify each one
to change the control name and anyway, this seems a very inelegant way
to do it!.

Anyone know of a way I could assign a function to the MouseDown event
on the property sheet ... e.g. =MyShiftCheck() which would assign True
or False to the global booShiftDown?  Perhaps something to do with
screen.activecontrol?

It'd be simple to place the function call to all the unbound controls
on the MouseDown event.

If I'm being very dumb here ...

a) not unusual

b) please be kind - I need lots of sympathy, I'm a Welsh Rugby
supporter!

JB
0
Reply jbguernsey 2/11/2011 2:27:46 PM

"jbguernsey" <jeff@angelsystems.co.uk> skrev i en meddelelse 
news:9a0fc97f-b4a7-47f8-9956-f6f9dffbee0c@4g2000yqo.googlegroups.com...
> Hi All
>
> I am playing around with a form with 280 unbound controls (7 days x 40
> time slots per day).  I'd like to be able to check the Shift status on
> each of these controls during the MouseDown event.  I can use the
> MouseDown event procedure:
>
> Private Sub Day101_MouseDown(Button As Integer, Shift As Integer, X As
> Single, Y As Single)
> If Shift = 1 Then
>    booShiftDown = True
> Else
>    booShiftDown = False
> End If
> End Sub
>
> but I'd have to copy this for each unbound control and modify each one
> to change the control name and anyway, this seems a very inelegant way
> to do it!.
>
> Anyone know of a way I could assign a function to the MouseDown event
> on the property sheet ... e.g. =MyShiftCheck() which would assign True
> or False to the global booShiftDown?  Perhaps something to do with
> screen.activecontrol?
>
> It'd be simple to place the function call to all the unbound controls
> on the MouseDown event.
>
> If I'm being very dumb here ...
>
> a) not unusual
>
> b) please be kind - I need lots of sympathy, I'm a Welsh Rugby
> supporter!
>
> JB

Sorry, no. I wouldn't claim to be an authoritative source, but as far as I 
know you cannot trap such an event at the form or screen levels.

In "real basic" you could've placed an indexed control array on your form 
with common event handling, ie. your 280 timeslot textboxes, but this is not 
supported in Access/VBA.




0
Reply Kaj 2/12/2011 2:51:12 PM


jbguernsey wrote:
>I am playing around with a form with 280 unbound controls (7 days x 40
>time slots per day).  I'd like to be able to check the Shift status on
>each of these controls during the MouseDown event.  I can use the
>MouseDown event procedure:
>
>Private Sub Day101_MouseDown(Button As Integer, Shift As Integer, X As
>Single, Y As Single)
>If Shift = 1 Then
>    booShiftDown = True
>Else
>    booShiftDown = False
>End If
>End Sub
>
>but I'd have to copy this for each unbound control and modify each one
>to change the control name and anyway, this seems a very inelegant way
>to do it!.
>
>Anyone know of a way I could assign a function to the MouseDown event
>on the property sheet ... e.g. =MyShiftCheck() which would assign True
>or False to the global booShiftDown?  Perhaps something to do with
>screen.activecontrol?
>
>It'd be simple to place the function call to all the unbound controls
>on the MouseDown event.
>
>If I'm being very dumb here ...
>
>a) not unusual
>
>b) please be kind - I need lots of sympathy, I'm a Welsh Rugby
>supporter!


Not dumb at all, and neither are rugby players  ;-)

The problem is that the MouseDown event knows how to call
the event procedure with all those arguments.  That
capabilit is lost when you put a function call in an event
property.

If all of your unbound controls are arranged in a tight
rectanglar grid pattern, then the way I deal with it is to
place a transparent command button exactly over the grid of
controls.  This way the transparent command button's
MouseDown event is called and the problem becomes how to
figure which unbound control the mouse is over.

Name the unbound controls with a numeric suffix that tells
you its row and column in the grid.  E.g:
   Day0000   Day0001   Day0002   Day0003
   Day0100   Day0101   Day0102   Day0103
   Day0200   Day0201   Day0202   Day0203

Then, assuming the grid of unbound controls under the big
button have no gaps between them and they are all the same
size, you can calculate the name of the control that has the
mouse over it:

Private Sub BigButton_MouseDown(Button As Integer, _
                Shift As Integer, X As  Single, Y As Single)
Dim Row As Integer, Col As Integer
Dim ControlName As String

   Row = Y \ Me.Day0000.Height
   Col = X \ Me.Day0000.Width
   ControlName = "Day" & Format(Row, "00") &  Format(Col,
"00")
        'set the value of the unbound control???
   Me(ControlName) = 1
        ' set the ShiftDown variable (Why is this useful?)
   If Shift = 1 Then
      booShiftDown = True
   Else
      booShiftDown = False
   End If
 End Sub

You probably want to do something else with the clicked
unbound control, but I think that above demonstrates all you
need to do whatever you want.

--
Marsh
0
Reply Marshall 2/12/2011 6:32:56 PM

On Feb 12, 6:32=A0pm, Marshall Barton <marshbar...@wowway.com> wrote:
> jbguernsey wrote:
> >I am playing around with a form with 280 unbound controls (7 days x 40
> >time slots per day). =A0I'd like to be able to check the Shift status on
> >each of these controls during the MouseDown event. =A0I can use the
> >MouseDown event procedure:
>
> >Private Sub Day101_MouseDown(Button As Integer, Shift As Integer, X As
> >Single, Y As Single)
> >If Shift =3D 1 Then
> > =A0 =A0booShiftDown =3D True
> >Else
> > =A0 =A0booShiftDown =3D False
> >End If
> >End Sub
>
> >but I'd have to copy this for each unbound control and modify each one
> >to change the control name and anyway, this seems a very inelegant way
> >to do it!.
>
> >Anyone know of a way I could assign a function to the MouseDown event
> >on the property sheet ... e.g. =3DMyShiftCheck() which would assign True
> >or False to the global booShiftDown? =A0Perhaps something to do with
> >screen.activecontrol?
>
> >It'd be simple to place the function call to all the unbound controls
> >on the MouseDown event.
>
> >If I'm being very dumb here ...
>
> >a) not unusual
>
> >b) please be kind - I need lots of sympathy, I'm a Welsh Rugby
> >supporter!
>
> Not dumb at all, and neither are rugby players =A0;-)
>
> The problem is that the MouseDown event knows how to call
> the event procedure with all those arguments. =A0That
> capabilit is lost when you put a function call in an event
> property.
>
> If all of your unbound controls are arranged in a tight
> rectanglar grid pattern, then the way I deal with it is to
> place a transparent command button exactly over the grid of
> controls. =A0This way the transparent command button's
> MouseDown event is called and the problem becomes how to
> figure which unbound control the mouse is over.
>
> Name the unbound controls with a numeric suffix that tells
> you its row and column in the grid. =A0E.g:
> =A0 =A0Day0000 =A0 Day0001 =A0 Day0002 =A0 Day0003
> =A0 =A0Day0100 =A0 Day0101 =A0 Day0102 =A0 Day0103
> =A0 =A0Day0200 =A0 Day0201 =A0 Day0202 =A0 Day0203
>
> Then, assuming the grid of unbound controls under the big
> button have no gaps between them and they are all the same
> size, you can calculate the name of the control that has the
> mouse over it:
>
> Private Sub BigButton_MouseDown(Button As Integer, _
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Shift As Integer, X As =A0Single, Y As Si=
ngle)
> Dim Row As Integer, Col As Integer
> Dim ControlName As String
>
> =A0 =A0Row =3D Y \ Me.Day0000.Height
> =A0 =A0Col =3D X \ Me.Day0000.Width
> =A0 =A0ControlName =3D "Day" & Format(Row, "00") & =A0Format(Col,
> "00")
> =A0 =A0 =A0 =A0 'set the value of the unbound control???
> =A0 =A0Me(ControlName) =3D 1
> =A0 =A0 =A0 =A0 ' set the ShiftDown variable (Why is this useful?)
> =A0 =A0If Shift =3D 1 Then
> =A0 =A0 =A0 booShiftDown =3D True
> =A0 =A0Else
> =A0 =A0 =A0 booShiftDown =3D False
> =A0 =A0End If
> =A0End Sub
>
> You probably want to do something else with the clicked
> unbound control, but I think that above demonstrates all you
> need to do whatever you want.
>
> --
> Marsh

Thanks Marsh.  I had already named the controls Day101, Day102 ...
Day140, Day201, Day202 ... Day240 etc so I can ascertain where I am on
the 'grid'.

I was afraid that there was no 'simple' solution.

The reason for the Shift stuff is that I'd like an 'easy' way for the
user to select a (vertical) block of 'cells' and I thought a Shift-
Click following the original click in a 'cell' would be nice and easy
(for the user).  I have found that the MouseOver event stuff is just
not reliable enough to use - it doesn't seem to be able to keep up
with swift mouse movements: therefore I don't use click and drag.

Anyway, thanks again for the idea,  I'll give it some thought and see
what transpires.

JB
0
Reply jbguernsey 2/12/2011 7:46:33 PM

>
> The reason for the Shift stuff is that I'd like an 'easy' way for the
> user to select a (vertical) block of 'cells' and I thought a Shift-
> Click following the original click in a 'cell' would be nice and easy
> (for the user). =A0I have found that the MouseOver event stuff is just
> not reliable enough to use - it doesn't seem to be able to keep up
> with swift mouse movements: therefore I don't use click and drag.
>
> Anyway, thanks again for the idea, =A0I'll give it some thought and see
> what transpires.
>
> JB- Hide quoted text -
>
> - Show quoted text -

Hi JB,

Because I use very generalized forms, I use these kind of techniques
quite intensively.

Let us assume you use the OnClick event to define the selected
controls.
Anyway, you have to catch the OnClick events of each of the 280
controls you have.
This is easily done by declaring:

Private Sub Day101_Click()
    On_Click Me, 101      or  On_Click Me, =93Day101=94
End Sub

Etc.

If 280 times is too much work, you can make a small VBA-routines, that
generates an a txt-file with all the necessary declarations that can
be included in the form module with copy/paste.

The On_Click procedure contains all the knowledge on how you want to
work with your controls. Using Me as a parameter has the advantage
that you can place this Sub in any module without loosing the
information of the used form, and you can generalize it for other
forms.

On the form you can define a unvisible Last_clicked control, whereas
the new_clicked control is passed as second parameter to the On_Click
sub.
In principle you now have enough information to do what you want.


Imb.

0
Reply imb4u (67) 2/15/2011 10:32:20 PM

On Feb 15, 10:32=A0pm, imb <im...@onsmail.nl> wrote:
> > The reason for the Shift stuff is that I'd like an 'easy' way for the
> > user to select a (vertical) block of 'cells' and I thought a Shift-
> > Click following the original click in a 'cell' would be nice and easy
> > (for the user). =A0I have found that the MouseOver event stuff is just
> > not reliable enough to use - it doesn't seem to be able to keep up
> > with swift mouse movements: therefore I don't use click and drag.
>
> > Anyway, thanks again for the idea, =A0I'll give it some thought and see
> > what transpires.
>
> > JB- Hide quoted text -
>
> > - Show quoted text -
>
> Hi JB,
>
> Because I use very generalized forms, I use these kind of techniques
> quite intensively.
>
> Let us assume you use the OnClick event to define the selected
> controls.
> Anyway, you have to catch the OnClick events of each of the 280
> controls you have.
> This is easily done by declaring:
>
> Private Sub Day101_Click()
> =A0 =A0 On_Click Me, 101 =A0 =A0 =A0or =A0On_Click Me, =93Day101=94
> End Sub
>
> Etc.
>
> If 280 times is too much work, you can make a small VBA-routines, that
> generates an a txt-file with all the necessary declarations that can
> be included in the form module with copy/paste.
>
> The On_Click procedure contains all the knowledge on how you want to
> work with your controls. Using Me as a parameter has the advantage
> that you can place this Sub in any module without loosing the
> information of the used form, and you can generalize it for other
> forms.
>
> On the form you can define a unvisible Last_clicked control, whereas
> the new_clicked control is passed as second parameter to the On_Click
> sub.
> In principle you now have enough information to do what you want.
>
> Imb.

Thanks lmb.  I appreciate your time and interest.

I'll have a go at your method.  Very nasty outbreak of work going on
here at present so it will have to wait for things to calm down ...

JB
0
Reply jbguernsey 2/18/2011 11:16:45 AM

5 Replies
197 Views

(page loaded in 0.296 seconds)

Similiar Articles:













7/17/2012 12:05:08 PM


Reply: