dbTalk Databases Forums  

Getting control names by passing the mouse over them.

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


Discuss Getting control names by passing the mouse over them. in the comp.databases.ms-access forum.



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

Default Getting control names by passing the mouse over them. - 04-03-2011 , 05:35 PM






I have a number of controls in the detail section of a form, each control
corresponding to an individual record in a table (Spaces). The controls are
all named something like "Space001", "Space002" ... "Space120". Got bored
after that There is a field in the table called "Selected".
When a drag the mouse over any number of controls, I want to change Selected
to true if it is false, and vice-versa.

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)

Dim Ctl As Control

If Button And acRightButton Then
For Each Ctl In Me.Section(acDetail).Controls
If X >= Ctl.left And X <= Ctl.left + Ctl.Width Then
If Y >= Ctl.top And Y <= Ctl.top + Ctl.Height Then
Call SaveSelect(CInt(right(Ctl.Name, 3)))
End If
End If
Next Ctl
End If

End Sub

Sub SaveSelect(SpaceID As Integer)

Dim MyDb As Database
Dim SQLStg As String
Dim SpaceSet As Recordset
Dim CtlSpace As Control

Set CtlSpace = Me.Controls("Space" & Format(SpaceID, "000"))

SQLStg = "SELECT QSpaces.* FROM QSpaces "
SQLStg = SQLStg & " WHERE SpaceTypeID = " & Nz(SpaceTypeID)
SQLStg = SQLStg & " AND SpaceNo = " & SpaceID & ";"

Set MyDb = CurrentDb
Set SpaceSet = MyDb.OpenRecordset(SQLStg)
Debug.Print SpaceID

With SpaceSet
.Edit
If !Selected = True Then
!Selected = False
CtlSpace.BackStyle = 0 ' Transparent
CtlSpace.BackColor = vbWhite
Else
!Selected = True
CtlSpace.BackStyle = 1 ' Opaque
CtlSpace.BackColor = vbRed
End If
.Update
.Close
Set SpaceSet = Nothing
End With

End Sub

Problem appears to be that as I drag the mouse over a single control, the
MouseMove keep "firing". How do I "switch it off" until I hit the next
control? Thanks
Phil

Reply With Quote
  #2  
Old   
Stuart McCall
 
Posts: n/a

Default Re: Getting control names by passing the mouse over them. - 04-03-2011 , 07:45 PM






"Phil" <phil (AT) stantonfamily (DOT) co.uk> wrote

Quote:
I have a number of controls in the detail section of a form, each control
corresponding to an individual record in a table (Spaces). The controls
are
all named something like "Space001", "Space002" ... "Space120". Got bored
after that There is a field in the table called "Selected".
When a drag the mouse over any number of controls, I want to change
Selected
to true if it is false, and vice-versa.

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)

Dim Ctl As Control

If Button And acRightButton Then
For Each Ctl In Me.Section(acDetail).Controls
If X >= Ctl.left And X <= Ctl.left + Ctl.Width Then
If Y >= Ctl.top And Y <= Ctl.top + Ctl.Height Then
Call SaveSelect(CInt(right(Ctl.Name, 3)))
End If
End If
Next Ctl
End If

End Sub

Sub SaveSelect(SpaceID As Integer)

Dim MyDb As Database
Dim SQLStg As String
Dim SpaceSet As Recordset
Dim CtlSpace As Control

Set CtlSpace = Me.Controls("Space" & Format(SpaceID, "000"))

SQLStg = "SELECT QSpaces.* FROM QSpaces "
SQLStg = SQLStg & " WHERE SpaceTypeID = " & Nz(SpaceTypeID)
SQLStg = SQLStg & " AND SpaceNo = " & SpaceID & ";"

Set MyDb = CurrentDb
Set SpaceSet = MyDb.OpenRecordset(SQLStg)
Debug.Print SpaceID

With SpaceSet
.Edit
If !Selected = True Then
!Selected = False
CtlSpace.BackStyle = 0 ' Transparent
CtlSpace.BackColor = vbWhite
Else
!Selected = True
CtlSpace.BackStyle = 1 ' Opaque
CtlSpace.BackColor = vbRed
End If
.Update
.Close
Set SpaceSet = Nothing
End With

End Sub

Problem appears to be that as I drag the mouse over a single control, the
MouseMove keep "firing". How do I "switch it off" until I hit the next
control? Thanks
Phil
Use a static variable to see if the control has changed since the last mouse
move notification:

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)

Static CtlName As String
Dim Ctl As Control

If Button And acRightButton Then
For Each Ctl In Me.Section(acDetail).Controls
If X >= Ctl.left And X <= Ctl.left + Ctl.Width Then
If Y >= Ctl.top And Y <= Ctl.top + Ctl.Height Then
If Ctl.Name <> CtlName Then
Call SaveSelect(CInt(right(Ctl.Name, 3)))
CtlName = Ctl.Name
End If
End If
End If
Next Ctl
End If

End Sub

Reply With Quote
  #3  
Old   
Phil
 
Posts: n/a

Default Re: Getting control names by passing the mouse over them. - 04-04-2011 , 05:07 PM



On 04/04/2011 01:45:41, "Stuart McCall" wrote:
Quote:
"Phil" <phil (AT) stantonfamily (DOT) co.uk> wrote in message
news:inaso6$2ah$1 (AT) speranza (DOT) aioe.org...
I have a number of controls in the detail section of a form, each control
corresponding to an individual record in a table (Spaces). The controls
are
all named something like "Space001", "Space002" ... "Space120". Got bored
after that There is a field in the table called "Selected".
When a drag the mouse over any number of controls, I want to change
Selected
to true if it is false, and vice-versa.


Problem appears to be that as I drag the mouse over a single control, the
MouseMove keep "firing". How do I "switch it off" until I hit the next
control? Thanks
Phil

Use a static variable to see if the control has changed since the last
mouse move notification:

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)

Static CtlName As String
Dim Ctl As Control

If Button And acRightButton Then
For Each Ctl In Me.Section(acDetail).Controls
If X >= Ctl.left And X <= Ctl.left + Ctl.Width Then
If Y >= Ctl.top And Y <= Ctl.top + Ctl.Height Then
If Ctl.Name <> CtlName Then
Call SaveSelect(CInt(right(Ctl.Name, 3)))
CtlName = Ctl.Name
End If
End If
End If
Next Ctl
End If

End Sub

Thanks Stuart. That bit works perfectly
Still having problems if the images are overlapping (or completely covering
each other). All my images are transparent, so I can see the image indeneath,
but not neccessarily be able to pick it up. Will do some more research ans
come back Thanks again
Phil

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.