Tab Control "Visible" Property (1 Viewer)

andmunn

Registered User.
Local time
Today, 12:17
Joined
Mar 31, 2009
Messages
195
Hi All,

I'm trying to get this working, however, being very inexperienced, can't make it work. I basically have several tabs, which some i want to hide depending on the value of "fkProcessID", i.e.//

Private Sub Form_Load()
If Me!fkProcessID = 23 Then
frmSample!TabCtl206.Page(1).Visible = True
Else
frmSample!TabCtl206.Page(1).Visible = False
End If

If Me!fkProcessID = 28 Then
frmSample!TabCtl206.Page(2).Visible = True
Else
frmSample!TabCtl206.Page(2).Visible = False
End If
End Sub

I get an error on above. Any advice?

Thanks,
Andrew.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:17
Joined
Aug 30, 2003
Messages
36,124
Don't refer to the tab control, just the page:

Me.Page1.Visible = True
 

andmunn

Registered User.
Local time
Today, 12:17
Joined
Mar 31, 2009
Messages
195
Thank you both of you - that did the trick. Here is the code that works:

If fkProcessID = 23 Then
Me.PF.Visible = True
End If

If fkProcessID = 28 Then
Me.CLF.Visible = True
End If

Note, i set the default property to both tabs as "not visible"..
 

MoxieCraz

Registered User.
Local time
Today, 15:17
Joined
Jun 8, 2010
Messages
29
I set my default visible property for all tabs to "YES" in hopes that if there is no data in the Combo78, then all tabs would show. What happens is whatever the last tab on the record was prior to creating a new record - it only shows that tab...until I change the Combo78. Any suggestions???

If Combo78 = "Graphics" Then
Me.Graphics.Visible = True
Me.Audio_Music.Visible = False
Me.Audio_Voice.Visible = False
Me.Video.Visible = False
Me.Text.Visible = False
End If
If Combo78 = "" Then
Me.Graphics.Visible = True
Me.Audio_Music.Visible = True
Me.Audio_Voice.Visible = True
Me.Video.Visible = True
Me.Text.Visible = True
End If
If Combo78 = "Audio-Music" Then
Me.Graphics.Visible = False
Me.Audio_Music.Visible = True
Me.Audio_Voice.Visible = False
Me.Video.Visible = False
Me.Text.Visible = False
End If
If Combo78 = "Audio-Voice" Then
Me.Graphics.Visible = False
Me.Audio_Music.Visible = False
Me.Audio_Voice.Visible = True
Me.Video.Visible = False
Me.Text.Visible = False
End If
If Combo78 = "Video" Then
Me.Graphics.Visible = False
Me.Audio_Music.Visible = False
Me.Audio_Voice.Visible = False
Me.Video.Visible = True
Me.Text.Visible = False
End If
If Combo78 = "Text" Then
Me.Graphics.Visible = False
Me.Audio_Music.Visible = False
Me.Audio_Voice.Visible = False
Me.Video.Visible = False
Me.Text.Visible = True
End If
End Sub
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:17
Joined
Aug 30, 2003
Messages
36,124
I'm guessing that code is in the update event of the combo. To have it fire when you change records, you'd need the same code in the current event (or have a function that gets called from both). You might want to look at Select/Case in VBA help; it would be more efficient for what you're doing.
 

DavidRBoyle

Registered User.
Local time
Today, 12:17
Joined
May 22, 2015
Messages
10
Just a little note regarding your VBA coding stye. It is best to leave the control visible and explicitly set the visibility, this mean the code doesn't need the explanation you have given it. Also you can often use the truth of a condition directly rather than using an if.

The bracketted expressions below return true or false and therefore can be directly assigned.

This

With Me
.PF.Visible = (fkProcessID = 23)
.CLF.Visible = (fkProcessID = 28)
end with

is therefore equivalent to your original code

If Me!fkProcessID = 23 Then
frmSample!TabCtl206.Page(1).Visible = True
Else
frmSample!TabCtl206.Page(1).Visible = False
End If

If Me!fkProcessID = 28 Then
frmSample!TabCtl206.Page(2).Visible = True
Else
frmSample!TabCtl206.Page(2).Visible = False
End If
 

DavidRBoyle

Registered User.
Local time
Today, 12:17
Joined
May 22, 2015
Messages
10
This is a bit better than MoxieCraze's code :)


Me.Graphics.Visible = ((Combo78 = "Graphics") or (Combo78 = ""))
Me.Audio_Music.Visible = (Combo78 = "Audio-Music") or (Combo78 = ""))
Me.Audio_Voice.Visible = ((Combo78 = "Audio-Voice") or (Combo78 = ""))
Me.Video.Visible = ((Combo78 = "Video") or (Combo78 = ""))
Me.Text.Visible = ((Combo78 = "Text") or (Combo78 = ""))
 

vbaInet

AWF VIP
Local time
Today, 20:17
Joined
Jan 22, 2010
Messages
26,374
This is a bit better than MoxieCraze's code :)
This is a pretty old thread (i.e. 2010) that you've replied to DavidRBoyle. :)

And yes you've written a pretty looking and very useful code but unfortunately not everyone knows about Logic Gates, specifically the OR gate.
 

Users who are viewing this thread

Top Bottom