Link to home
Create AccountLog in
Avatar of JohnRobinAllen
JohnRobinAllenFlag for Canada

asked on

Set Default Button in a VBA form

I am working with VBA in a Word document. I have a form that contains a message and up to three buttons beneath the message so the user can choose what to do. I want to make one of the buttons be the default button that I specify with the integer variable DefaultButton. None of the buttons has a set default,  and I am trying to use this routine to specify which button should be the default:
Select Case DefaultButton
            Case Is = 0
                  frmJRABox.cbButton1.Default = True
            Case Is = 1
                  frmJRABox.cbButton2.Default = True
            Case Is = 2
                  frmJRABox.cbTranslate.Default = True
      End Select

When I step through the code it goes to the specified line, but the result is nil. Nothing gets specified as the default button.

Can anyone suggest what I am doing that prevents the above code from working?
I’ll try any suggestions. Thanks for any help.
     JRA
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi John Robin,

It is probably working, but the default button doesn't work in the way that you would expect. In general the events for command button that has the focus will fire when the enter is pressed. The default button's event will only fire if it or a non-command button control has the focus.
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of JohnRobinAllen

ASKER

Thanks again. I have a few things to do right now but will implement your solution in half an hour. I'm sure you have found the solution.
      j.r.
The method works like a charm. I originally thought the question was worth 250 points because I thought at least two persons might suggest successful answers, each worth 250 points.
      Your method is very important for fixing what I consider is a bug in VBA, and that is worth the full 500 points.
     With gratitude,
     John Robin
The method works like a charm. I originally thought the question was worth 250 points because I thought at least two persons might suggest successful answers, each worth 250 points.
      Your method is very important for fixing what I consider is a bug in VBA, and that is worth the full 500 points.
     With gratitude,
     John Robin