?
Solved

switching titles during a mouse over event

Posted on 2006-04-05
9
Medium Priority
?
165 Views
Last Modified: 2010-04-07
hi i have 2 command buttons. command1 and command2.

i want it so that when i move the mouse over 1 of them, the 2 buttons switch captions.

for example when command1 says "im smart" and command2 says "im stupid" i want it so that when the user puts the mouse over command1, the 2 buttons switch captions so that the user cant click on "im smart"

how do i do that?
0
Comment
Question by:jungle_man10000
  • 4
6 Comments
 
LVL 4

Expert Comment

by:g_johnson
ID: 16381387
try putting this in the mousemove event for each command button

if command1.caption = "im smart" then
      command1.caption = "im stupid"
      command2.caption = "im smart"
else
     command1.caption = "im smart"
     command2.caption = "im stupid"
endif
0
 
LVL 4

Expert Comment

by:g_johnson
ID: 16381399
oops  actually you'll need to modify that just a bit
i'll be right back with it
0
 
LVL 4

Accepted Solution

by:
g_johnson earned 540 total points
ID: 16381469
This code makes it just recognize the mouse move one time each time you pass over a button

Option Explicit
Dim intLastButton As Integer

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

If intLastButton = 0 Then
    If Command1.Caption = "im smart" Then
          Command1.Caption = "im stupid"
          Command2.Caption = "im smart"
    Else
         Command1.Caption = "im smart"
         Command2.Caption = "im stupid"
    End If
   
    intLastButton = 1
    Command1.SetFocus
End If

End Sub


Private Sub Command2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If intLastButton = 0 Then
    If Command1.Caption = "im smart" Then
          Command1.Caption = "im stupid"
          Command2.Caption = "im smart"
    Else
         Command1.Caption = "im smart"
         Command2.Caption = "im stupid"
    End If
    intLastButton = 2
    Command2.SetFocus
End If

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    intLastButton = 0
End Sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 76

Expert Comment

by:GrahamSkan
ID: 16381479
Option Explicit
Dim bHoldOff As Boolean

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim strMyCaption As String
If bHoldOff = False Then
    strMyCaption = Command1.Caption
    Command1.Caption = Command2.Caption
    Command2.Caption = strMyCaption
    bHoldOff = True
End If
End Sub

Private Sub Command2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim strMyCaption As String
    If bHoldOff = False Then
        strMyCaption = Command2.Caption
        Command2.Caption = Command1.Caption
        Command1.Caption = strMyCaption
        bHoldOff = True
    End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    bHoldOff = False
End Sub
0
 

Author Comment

by:jungle_man10000
ID: 16381639
wow dat was fast thx

can u tell me how to do teh same thing when people use the tab button
like if the tab focus is on one of the buttons the same thing happens?

lol im trynna make a unwinnable idiot test
0
 
LVL 4

Expert Comment

by:g_johnson
ID: 16381736
put the same code in the gotfocus event of each button
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question