Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-access > #796 > unrolled thread

Getting control names by passing the mouse over them.

Started by"Phil" <phil@stantonfamily.co.uk>
First post2011-04-03 23:35 +0100
Last post2011-04-04 23:07 +0100
Articles 3 — 2 participants

Back to article view | Back to comp.databases.ms-access


Contents

  Getting control names by passing the mouse over them. "Phil" <phil@stantonfamily.co.uk> - 2011-04-03 23:35 +0100
    Re: Getting control names by passing the mouse over them. "Stuart McCall" <smccall@myunrealbox.com> - 2011-04-04 01:45 +0100
      Re: Getting control names by passing the mouse over them. "Phil" <phil@stantonfamily.co.uk> - 2011-04-04 23:07 +0100

#796 — Getting control names by passing the mouse over them.

From"Phil" <phil@stantonfamily.co.uk>
Date2011-04-03 23:35 +0100
SubjectGetting control names by passing the mouse over them.
Message-ID<inaso6$2ah$1@speranza.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.

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

[toc] | [next] | [standalone]


#801

From"Stuart McCall" <smccall@myunrealbox.com>
Date2011-04-04 01:45 +0100
Message-ID<Ww8mp.2908$Pi.167@newsfe22.ams2>
In reply to#796
"Phil" <phil@stantonfamily.co.uk> wrote in message 
news:inaso6$2ah$1@speranza.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.
>
> 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

[toc] | [prev] | [next] | [standalone]


#810

From"Phil" <phil@stantonfamily.co.uk>
Date2011-04-04 23:07 +0100
Message-ID<indfed$dmo$1@speranza.aioe.org>
In reply to#801
On 04/04/2011 01:45:41, "Stuart McCall" wrote:
> "Phil" <phil@stantonfamily.co.uk> wrote in message
> news:inaso6$2ah$1@speranza.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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.databases.ms-access


csiph-web