dbTalk Databases Forums  

Check the MouseDown Shift status from a function

comp.databases.ms-access comp.databases.ms-access


Discuss Check the MouseDown Shift status from a function in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
jbguernsey
 
Posts: n/a

Default Check the MouseDown Shift status from a function - 02-11-2011 , 08:27 AM






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

Reply With Quote
  #2  
Old   
Kaj Julius
 
Posts: n/a

Default Re: Check the MouseDown Shift status from a function - 02-12-2011 , 08:51 AM






"jbguernsey" <jeff (AT) angelsystems (DOT) co.uk> skrev i en meddelelse
news:9a0fc97f-b4a7-47f8-9956-f6f9dffbee0c (AT) 4g2000yqo (DOT) googlegroups.com...
Quote:
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.

Reply With Quote
  #3  
Old   
Marshall Barton
 
Posts: n/a

Default Re: Check the MouseDown Shift status from a function - 02-12-2011 , 12:32 PM



jbguernsey wrote:
Quote:
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

Reply With Quote
  #4  
Old   
jbguernsey
 
Posts: n/a

Default Re: Check the MouseDown Shift status from a function - 02-12-2011 , 01:46 PM



On Feb 12, 6:32*pm, Marshall Barton <marshbar... (AT) wowway (DOT) com> wrote:
Quote:
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
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

Reply With Quote
  #5  
Old   
imb
 
Posts: n/a

Default Re: Check the MouseDown Shift status from a function - 02-15-2011 , 04:32 PM



Quote:
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- 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, “Day101”
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.

Reply With Quote
  #6  
Old   
jbguernsey
 
Posts: n/a

Default Re: Check the MouseDown Shift status from a function - 02-18-2011 , 05:16 AM



On Feb 15, 10:32*pm, imb <im... (AT) onsmail (DOT) nl> wrote:
Quote:
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- 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, “Day101”
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

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.