Hide cmb on main form based on which tab selected.

G

Guest

I have a form with tabs for some subforms. On the main form I have buttons
to do certain actions on the subforms. I would like to have some VBA code
that would "hide" the buttons that don't apply to the subforms on that tab.

So if page(0) is active on the tab form then button PPDNEW would be hidden.
If page(1) is active then button PPDNEW is visible and HEPNEW is hidden.

I have tried all sort of things on the TAB forms or the ON CURRENT event of
the main form.

TIA

Vanya
 
A

Allen Browne

Use the Change event of the tab control to set the Visible property of the
buttons.

The example below assumes cmdNext and cmdPrior should be shown only if the
selected page of Tab1 is Page0. If the button you are attempting to hide has
focus, you need to specify something else to set focus to.

Private Sub tab1_Change()
On Error GoTo Err_Handler
'Purpose: Show/hide the previous/next buttons.
Dim bShow As Boolean
Dim lngKt As Long

bShow = Nz(Me.tab1.Value = Me.Page0.PageIndex, True)

If Me.cmdPrior.Visible <> bShow Then
Me.cmdPrior.Visible = bShow
Me.cmdNext.Visible = bShow
End If

Exit_Handler:
Exit Sub

Err_Handler:
Select Case Err.Number
Case 2164&, 2165& 'Can't disable/hide the control with focus.
Me.[SomeOtherControl].SetFocus
lngKt = lngKt + 1&
If lngKt < 3& Then
Resume
Else
Resume Exit_Handler
End If
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Exit_Handler
End Select
End Sub
 
G

Guest

---- click on the blank part of the tab heading to get the
tab properties.
not in the body of the page (which give you the form detail section)
not on the actual tab (which give you the page properties)

(david)
 
G

Guest

Alan & David,

Many thanks gents, that got me what I needed. I appreciate your
willingness to share your knowledge with us neophytes!

Vanya
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top