Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 Default buttons on a subform - How can I correct this?

Status
Not open for further replies.

SBendBuckeye

Programmer
May 22, 2002
2,166
0
0
US
Its a long story, but I have 2 separate subforms which contain different command buttons. When opened separately, each one has a default (I didn't set it) button with a darker shadow around it. When I combine them as subforms on my main form, each subform still displays a button with a darker shadow around so I have two instead of one.

What do I need to do to only have one? I have setfocus on the one I really want to have it, but the remaining one still has a darker shadow around it.

Any help would be greatly appreciated!
 
Regarding the subform with the unrequired button...

Open in design view. Select the button you wish to "loose" and set its Visible property to No. That way you have make no irreversible changes to the form. However one word of warning. You should examine the code module in the back of the subform to ensure that there is no code there that operates to SetFocus to the button. Setting the Focus to an invisible button will cause an error!

If there is a situation within the Appllication where that subform is required to open with its command button visible then you would need an alternative approach.


In the Open Event for the form add some code to test if the other subform is open and act accordingly.

Assuming that the forms are called subform_A with the button you want to keep and subform_B with the button you don't want to see AND that you have not altered the Visible property of the button, then:

In the code module of subform_B:


Private Sub Form_Open()

If IsLoaded("subform_A") Then
cmdButton.Visible = False
End If

End Sub


The IsLoaded function should exist in a Public Module in your Application.. If your haven't got it you can locate a copy of it in the Microsoft Solutions application's modIsLoaded module.

Regards
Rod

 
I didn't explain myself very well. I want both buttons to be active, but only want one to have the darker shadow around it signifying that it has been selected.

To recreate my problem:
Create 2 forms each of which have a couple of command
buttons on them
If you open them one of the buttons will have a darker
shadow under it than the others because it is the
default control
Create a new form and drag the other 2 forms onto the
third one as subforms
When you open it up, you will notice that each of the
subforms shows one of its buttons with a darker
shadow, but since they are now subordinate to the
main form, I only want one of them to have the
darker shadow.

Let me know if you have specific questions.
 
Try this out. For the subform containing the command button that you want to have as the default, in properties of the button control set its default property to YES and the other button on the same form to No. On the subform that you do not want to have any default buttons, change their default property to NO.

Now that the properties are set to open the way you want you can use the Enter and Exit Events of the subform control on the main form to display the default properties for the command buttons. Set the Enter event on the subform control where the default properties are set to NO for both buttons. Put in the following event procedure code for the button that you want to be the default:

Form!frmMainForm!frmSubFormCONTROL!cmdButtonNameOnSubForm.Default = True

Now when you click on the subform the button will display the characteristics of the shaded default. You can use the Exit event on the SubFormControl to set the value back to no when the control uses the focus.
 

Sorry, made a typo, it should read:

Forms! (should have an S at the end of form, as in plural, and the code is all one line)

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top