![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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 |
#3
| |||
| |||
|
|
"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 |
![]() |
| Thread Tools | |
| Display Modes | |
| |