Tab.Visible=True

B

briank

Hello.
I have a subform with four pages. I would like to make Page 4 visible only
if there data within a field (Feeder) in the linked subform. So if the
subform within the Page 4 has data then the page is visible - if no data then
the page would be hidden. Any help would be appreciated.

Private Sub Form_Current()
If Me.TabCtl178.Pages(4)![Feeder] Is Not Null Then
TabCtl178.Pages(4).Visible = True
End If
If Me.TabCtl178.Pages(4)![Feeder] Is Null Then
TabCtl178.Pages(4).Visible = False
End If
 
M

Marshall Barton

briank said:
I have a subform with four pages. I would like to make Page 4 visible only
if there data within a field (Feeder) in the linked subform. So if the
subform within the Page 4 has data then the page is visible - if no data then
the page would be hidden. Any help would be appreciated.

Private Sub Form_Current()
If Me.TabCtl178.Pages(4)![Feeder] Is Not Null Then
TabCtl178.Pages(4).Visible = True
End If
If Me.TabCtl178.Pages(4)![Feeder] Is Null Then
TabCtl178.Pages(4).Visible = False
End If


Two serious issues here.

The Is Null and Is Not Null is an SQL operator. In VBA you
need to use the IsNull function.

The reference to a control is not affected by a tab control.

All that code can be boiled down to one line:

TabCtl178.Pages(4).Visible = Not IsNull(Me![Feeder])
 
B

briank

Thanks for the correction and proper code. Upon using this code I noticed
that the term "Feeder" was used in my form and in two subforms as well. I
would like to isolate the "Feeder" number to the subform
"sbfrmSensitiveCustomer". I have tried altering your code to include this as
follows:
TabCtl178.Pages(4).Visible = Not
IsNull(Me.Form!sbfrmSensitiveCustomer.[Feeder])

However when I try to switch from the form's design view to form view Access
won't allow it. Can you comment?

Marshall Barton said:
briank said:
I have a subform with four pages. I would like to make Page 4 visible only
if there data within a field (Feeder) in the linked subform. So if the
subform within the Page 4 has data then the page is visible - if no data then
the page would be hidden. Any help would be appreciated.

Private Sub Form_Current()
If Me.TabCtl178.Pages(4)![Feeder] Is Not Null Then
TabCtl178.Pages(4).Visible = True
End If
If Me.TabCtl178.Pages(4)![Feeder] Is Null Then
TabCtl178.Pages(4).Visible = False
End If


Two serious issues here.

The Is Null and Is Not Null is an SQL operator. In VBA you
need to use the IsNull function.

The reference to a control is not affected by a tab control.

All that code can be boiled down to one line:

TabCtl178.Pages(4).Visible = Not IsNull(Me![Feeder])
 
M

Marshall Barton

You are now using the Form property in the wrong place. It
should be:

TabCtl178.Pages(4).Visible = _
Not IsNull(Me.sbfrmSensitiveCustomer.Form!Feeder)

Don't forget that sbfrmSensitiveCustomer must be the name of
the subform **control** on the main form (it might be
different from the name of the form object it will display).

It might help you isolate syntax errors if you would do two
things. Make sure that
OPTION EXPLICIT
is the first line in all code modules. This tells VBA to
let you know when you use a variable that you forgot to
declare and that may cause trouble when the code executes.

The second thing is to compile (Debug menu) immediately
after you think you have finished making a change. This
will let you know about syntax errors before you get into
the larger, more confusing, context when using your forms
and reports.

Another thing you should do is to make sure that you switch
any open form or report to design view before changing its
code module. If a form/report is still open in a normal
view, Access may get confused about which internal copy of
the module is being changed and corrupt the module.
--
Marsh
MVP [MS Access]

Thanks for the correction and proper code. Upon using this code I noticed
that the term "Feeder" was used in my form and in two subforms as well. I
would like to isolate the "Feeder" number to the subform
"sbfrmSensitiveCustomer". I have tried altering your code to include this as
follows:
TabCtl178.Pages(4).Visible = Not
IsNull(Me.Form!sbfrmSensitiveCustomer.[Feeder])

However when I try to switch from the form's design view to form view Access
won't allow it. Can you comment?

Marshall Barton said:
briank said:
I have a subform with four pages. I would like to make Page 4 visible only
if there data within a field (Feeder) in the linked subform. So if the
subform within the Page 4 has data then the page is visible - if no data then
the page would be hidden. Any help would be appreciated.

Private Sub Form_Current()
If Me.TabCtl178.Pages(4)![Feeder] Is Not Null Then
TabCtl178.Pages(4).Visible = True
End If
If Me.TabCtl178.Pages(4)![Feeder] Is Null Then
TabCtl178.Pages(4).Visible = False
End If


Two serious issues here.

The Is Null and Is Not Null is an SQL operator. In VBA you
need to use the IsNull function.

The reference to a control is not affected by a tab control.

All that code can be boiled down to one line:

TabCtl178.Pages(4).Visible = Not IsNull(Me![Feeder])
 
B

briank

Marsh, I have no doubt that you are explaining this correctly but I am
missing something here. I inserted the code below into the OnCurrent Event
in sbfrmSensitiveCustomer. I debugged and still find that I cannot switch
from design to form view. Am I inserting this code into the correct location?

Private Sub Form_Current()
Option Explicit
TabCtl178.Pages(4).Visible = Not IsNull(Me.sbfrmSensitiveCustomer.Form!Feeder)
End Sub

Main Form: frmMasterSelector
Tab: TabCtl178
Page1: sbfrm1
Page2: sbfrm2, sbfrm3
Page3: sbfrm4
Page4: sbfrmSensitiveCustomer


Marshall Barton said:
You are now using the Form property in the wrong place. It
should be:

TabCtl178.Pages(4).Visible = _
Not IsNull(Me.sbfrmSensitiveCustomer.Form!Feeder)

Don't forget that sbfrmSensitiveCustomer must be the name of
the subform **control** on the main form (it might be
different from the name of the form object it will display).

It might help you isolate syntax errors if you would do two
things. Make sure that
OPTION EXPLICIT
is the first line in all code modules. This tells VBA to
let you know when you use a variable that you forgot to
declare and that may cause trouble when the code executes.

The second thing is to compile (Debug menu) immediately
after you think you have finished making a change. This
will let you know about syntax errors before you get into
the larger, more confusing, context when using your forms
and reports.

Another thing you should do is to make sure that you switch
any open form or report to design view before changing its
code module. If a form/report is still open in a normal
view, Access may get confused about which internal copy of
the module is being changed and corrupt the module.
--
Marsh
MVP [MS Access]

Thanks for the correction and proper code. Upon using this code I noticed
that the term "Feeder" was used in my form and in two subforms as well. I
would like to isolate the "Feeder" number to the subform
"sbfrmSensitiveCustomer". I have tried altering your code to include this as
follows:
TabCtl178.Pages(4).Visible = Not
IsNull(Me.Form!sbfrmSensitiveCustomer.[Feeder])

However when I try to switch from the form's design view to form view Access
won't allow it. Can you comment?

Marshall Barton said:
briank wrote:
I have a subform with four pages. I would like to make Page 4 visible only
if there data within a field (Feeder) in the linked subform. So if the
subform within the Page 4 has data then the page is visible - if no data then
the page would be hidden. Any help would be appreciated.

Private Sub Form_Current()
If Me.TabCtl178.Pages(4)![Feeder] Is Not Null Then
TabCtl178.Pages(4).Visible = True
End If
If Me.TabCtl178.Pages(4)![Feeder] Is Null Then
TabCtl178.Pages(4).Visible = False
End If


Two serious issues here.

The Is Null and Is Not Null is an SQL operator. In VBA you
need to use the IsNull function.

The reference to a control is not affected by a tab control.

All that code can be boiled down to one line:

TabCtl178.Pages(4).Visible = Not IsNull(Me![Feeder])
 
Top