Hover-button effect

  • Thread starter Thread starter nh
  • Start date Start date
N

nh

Perhaps stupidly, when I started writing a database I
broke with tradition and made my own 'hover-buttons'
instead of using command buttons:

Basically, the buttons are text boxes using the following
code on the form...

Private Sub Form_Open()
Me!MyButton1.BorderStyle = 0
Me!MyButton2.BorderStyle = 0
End Sub
Private Sub Detail_MouseMove()
Me!MyButton1.BorderStyle = 0
Me!MyButton2.BorderStyle = 0
End Sub
Private Sub MyButton1_Click()
DoCmd.OpenForm.....
End Sub
Private Sub MyButton1_MouseMove()
Me!MyButton.BorderStyle = 1
End Sub

I love the effect, but the database has grown into
somthing much larger than originally planned. I now find
myself spending hours just getting new buttons to look
like the others. Unfortunately its too late to go back and
change them all to command buttons.

Each new button not only requires its own event
precedures, but modifications to all of the others'.

Can anyone suggest a way of making the task of creating a
new button simpler? Is it possible the 'save' or 'copy'
one button as a control with its code attached, and keep
re-using it? Am I stuck with it the way it is?

Thanks

Nick
 
Hi,

You could create a procedure that will loop through all the controls on the
form and pass the active Hover Button (if any) into the procedure and do a
test for it. You could then place something in all the Hover-Buttons
controls 'Tag' property (found under the 'Other' tab in properties) to
indicate it is a hover button. I used (simply :-)) HoverButton.

Private Sub FormatButtons(strProcedureID As String, Optional ctlCurrent As
Control)

Dim ctlLoop As Control
Static strCheckString As String

' Check the string passed in against the procedure ID
' If they are the same, the mouse is still over the same control
' Doing this check prevents looping through controls everytime the mouse
moves
If strCheckString = strProcedureID Then Exit Sub

' Loop through all the controls on the form
For Each ctl In Me.Controls
' Check to see if the control in the loop is a hover button
If ctlLoop.Tag = "HoverButton" Then
' Check to see if a button has been passed in
If ctlCurrent Is Nothing Then
' No control has been passed in - not on a hover button
' Set border style to 0
ctlLoop.BorderStyle = 0
Else
' Check to see if the control in the loop is the hover
button passed into the sub
If ctlLoop.Name = ctlCurrent.Name Then
' Make this control 'look' active
ctlLoop.BorderStyle = 1
Else
' Make this control 'look' in-active
ctlLoop.BorderStyle = 0
End If
End If
End If
Next

End Sub

To call this procedure to make a button active (in the buttons mousemove for
example) then do the following (replacing the neccesarry names)

Private Sub MyButton1_MouseMove()

' Format the buttons on the form making MyButton1 look active
Call FormatButtons(Me!MyButton1.Name, Me!MyButton1)

End Sub

To call this procedure to clear an active button (when hovering over detail
for example), dont pass a control into the sub, Just the procedure ID. E.g.

Private Sub Detail_MouseMove()

Call FormatButtons("Detail_MouseMove")

End Sub

The procedure ID is just a string to identify the procedure that called
FormatButtons. This can be anything, but i would recommend it to be the same
as the control name when the procedure is passing a control (as used with
the .Name property) and using the procedures full name when not passing a
control. This just stops entering duplicate ID's - if this happens, the
controls wont update because the sub will stop before it gets to looping
through the controls.

I have not tested the code above, but you will only have to add the Call
line to a new hover buttons MouseMove procedure (the sub takes over
resetting all other controls).

Good luck.

HTH,

Neil.
 
nh said:
Perhaps stupidly, when I started writing a database I
broke with tradition and made my own 'hover-buttons'
instead of using command buttons:

Basically, the buttons are text boxes using the following
code on the form...

Private Sub Form_Open()
Me!MyButton1.BorderStyle = 0
Me!MyButton2.BorderStyle = 0
End Sub
Private Sub Detail_MouseMove()
Me!MyButton1.BorderStyle = 0
Me!MyButton2.BorderStyle = 0
End Sub
Private Sub MyButton1_Click()
DoCmd.OpenForm.....
End Sub
Private Sub MyButton1_MouseMove()
Me!MyButton.BorderStyle = 1
End Sub

I love the effect, but the database has grown into
somthing much larger than originally planned. I now find
myself spending hours just getting new buttons to look
like the others. Unfortunately its too late to go back and
change them all to command buttons.

Each new button not only requires its own event
precedures, but modifications to all of the others'.

Can anyone suggest a way of making the task of creating a
new button simpler? Is it possible the 'save' or 'copy'
one button as a control with its code attached, and keep
re-using it? Am I stuck with it the way it is?


Neil's approach can be taken to another level by placing the
function call in the OnMouseMove property;

=FormatButtons(x, "buttonname")

so you don't even need to create an event procedure for each
button.

I haven't thought it through, but I think you can avoid
using a loop by having a static variable to keep track of
the button with the special effect.
 
Back
Top