i have 6 command buttons in a continous form, cmd buttons used for sorting some fields in my form. how to make the cmd button that user click it is determined to knows which cmd button is clicked (Ordered by which cmd).
How do you NOT know which button was clicked? Like, say I have a button called cmdMyButton. Then I'll have code like . . .
Code:
Private Sub cmdMyButton_Click()
msgbox "The button clicked is called " & me.cmdMyButton.Name
msgbox "It's type is: " & typename(Me.cmdMyButton)
End Sub
. . . so the button clicked has its name in the event handler. I don't understand how you can not know which button it was.
Or have you set the OnClick property of the button to something like . . .
Code:
"=SomeOtherFunction()"
. . . rather than . . .
Code:
"[Event Procedure]"
In that case, check out the Access.Form.ActiveControl property, which returns a reference to the object on the form that has the focus.
Hope this helps,
Private Sub Form_Timer()
If Me.OffFilterBtn.ForeColor = vbRed Then
Me.OffFilterBtn.ForeColor = vbBlue
Me.OffFilterBtn.BackStyle = 1
Me.OffFilterBtn.FontSize = 18
Else
Me.OffFilterBtn.ForeColor = vbRed
Me.OffFilterBtn.BackStyle = 0
Me.OffFilterBtn.FontSize = 12
End If
End Sub
and
Code:
Private Sub Form_Current()
Me.TimerInterval = 500 'twice per second
End Sub
The code you posted is not run by a command button click. To identify a button click we need to find the code that runs when that button is clicked. That code will have a signature like . . .
Code:
Private Sub [I]ButtonName[/I]_Click()
. . . if the click is handled in VBA, but the button may also run a macro.