How to create a shortcut key to evoke a built event

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • beacon
    Contributor
    • Aug 2007
    • 579

    How to create a shortcut key to evoke a built event

    Hi, this is probably fairly easy, but I don't have a ton of experience with Visual Basic and I haven't been able to find the answer I'm looking for online or in any of my books.

    First, let me ask this. Is there a way, sans code, to cause a radio button with a true value to become false again? I guess what I'm asking is whether or not you can press F5 or double-click the radio button to make it return to a false value.

    If the answer is no to the previous question, how can I set up my radio button(s) to where they will be returned to false if I press some key on the keyboard?

    I tried the double-click event and wrote code to set the button back to false, but that didn't work out so well. You have to double-click and hold, then drag your mouse away from the button to get it to work.

    Oh, I'm not sure if this is taboo or against the rules, but I'm using the Visual Basic Editor in MS Word 2003. And this is a work project, not a homework assignment I assure you.

    Any ideas?? Anyone...anyone ...Bueller...Bu eller.
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by beacon
    Hi, this is probably fairly easy, but I don't have a ton of experience with Visual Basic and I haven't been able to find the answer I'm looking for online or in any of my books.

    Any ideas?? Anyone...anyone ...Bueller...Bu eller.
    You've seen "Ferris Bueller's Day off", I suppose;-)

    Can you tell us little more? Above is great but programatically what is happening?

    for the Radio button to become false again, or to not have focus (which is what can happen in code) is there another event that goes through.
    .

    Please stay tuned if you ahven;t heard anything from me. Other experts will likely see this and can come to your aid also. You can also do a MouseMove event to get it to revert to false also.

    How many radio buttons are there?

    In a bit!

    Comment

    • QVeen72
      Recognized Expert Top Contributor
      • Oct 2006
      • 1445

      #3
      Hi,

      Write this code for all the Option-button's KeyUp event:

      [code=vb]
      Private Sub Option1_KeyUp(K eyCode As Integer, Shift As Integer)
      If KeyCode = vbKeyEscape Then
      Option1.Value = False
      End If
      End Sub
      [/code]

      So, when User has Selected, an Option and he presses Escape, the Option is not Selected.
      Alternatively, you can write in Form's Key-Up event also , make value =False for all the option buttons (with Form's KeyPreView=True )


      Regards
      Veena

      Comment

      • beacon
        Contributor
        • Aug 2007
        • 579

        #4
        Write this code for all the Option-button's KeyUp event:

        [code=vb]
        Private Sub Option1_KeyUp(K eyCode As Integer, Shift As Integer)
        If KeyCode = vbKeyEscape Then
        Option1.Value = False
        End If
        End Sub
        [/code]
        This is what I typed in using your code idea:
        [code=vb]
        Private Sub OptionButton11_ KeyUp(KeyCode As Integer, Shift As Integer)
        If KeyCode = vbKeyEscape Then
        OptionButton11. Value = False
        End If
        End Sub
        [/code]

        And this is the error message I received when I compiled it:
        Compile Error:
        Procedure declaration does not match description of event or procedure having the same name.
        Previously, when I attempted to code this myself using the double click event, this is the code I used:
        [code=vb]
        Private Sub OptionButton11_ DblClick(ByVal Cancel As MSForms.ReturnB oolean)
        If OptionButton11. Value = True Then
        OptionButton11. Value = False
        End Sub
        [/code]

        When I use the above code, you have to double click on the radio button with the mouse, hold down the mouse button on the second click, and then drag your mouse to a white area before releasing in order to get it to clear. Basically, it's a pain in my Bueller (just to keep the reference going). I was hoping to set up code that will enable me to set up a button that will essentially do the same thing, but without having to click on it.

        We use another program at my work that allows you to do this by pressing F5 and I was really hoping to be able to setup the F5 key to evoke the same event when pressed using this form. Please keep in mind that this is a Word Document using Word's VBA editor and that it will be used across a shared network.

        I have a bunch of radio buttons, but there are a lot of different groups and I would really rather give each of them the same code than create an event that clears them all (don't know if that's possible, but I thought I'd throw that out there because it won't benefit me).

        Thanks for all you do...each and every one of you...whoever you may be.

        Comment

        • QVeen72
          Recognized Expert Top Contributor
          • Oct 2006
          • 1445

          #5
          Hi,

          Sorry, My Code was for VB6..

          Regards
          Veena

          Comment

          • beacon
            Contributor
            • Aug 2007
            • 579

            #6
            Originally posted by QVeen72
            Hi,

            Sorry, My Code was for VB6..

            Regards
            Veena
            Do you know if there's a work around maybe to get it to mesh with the VBA editor in Word?

            Is there a good reference site I can go to to find more info?

            Comment

            Working...