By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,644 Members | 2,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,644 IT Pros & Developers. It's quick & easy.

How to create a shortcut key to evoke a built event

beacon
100+
P: 579
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...Bueller.
Nov 27 '07 #1
Share this Question
Share on Google+
5 Replies


Dököll
Expert 100+
P: 2,364
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...Bueller.
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!
Nov 30 '07 #2

QVeen72
Expert 100+
P: 1,445
Hi,

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

Expand|Select|Wrap|Line Numbers
  1. Private Sub Option1_KeyUp(KeyCode As Integer, Shift As Integer)
  2.     If KeyCode = vbKeyEscape Then
  3.         Option1.Value = False
  4.     End If
  5. End Sub
  6.  
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
Nov 30 '07 #3

beacon
100+
P: 579
Write this code for all the Option-button's KeyUp event:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Option1_KeyUp(KeyCode As Integer, Shift As Integer)
  2.     If KeyCode = vbKeyEscape Then
  3.         Option1.Value = False
  4.     End If
  5. End Sub
  6.  
This is what I typed in using your code idea:
Expand|Select|Wrap|Line Numbers
  1. Private Sub OptionButton11_KeyUp(KeyCode As Integer, Shift As Integer)
  2.     If KeyCode = vbKeyEscape Then
  3.         OptionButton11.Value = False
  4.     End If
  5. End Sub
  6.  
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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub OptionButton11_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
  2.     If OptionButton11.Value = True Then
  3.         OptionButton11.Value = False
  4. End Sub
  5.  
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.
Dec 1 '07 #4

QVeen72
Expert 100+
P: 1,445
Hi,

Sorry, My Code was for VB6..

Regards
Veena
Dec 2 '07 #5

beacon
100+
P: 579
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?
Dec 3 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.