The rundown: I'm creating a database for collecting internal combustion engine data. I'm new to ms access and struggled through the one programming class I ever took. I managed to get this code working but I'm sure there is a more efficient way of doing what I want.
I have two combo boxes and two tab controls. I only want the second combo box visible when certain values are selected and I only want pages on the tabs visible when certain values are selected again. I greatly appreciate any truncating that can be done.
Code:
Option Compare Database
Private Sub Combo1_Change()
'Makes all pages invisible
For Each p In TabCtl_1.Pages
p.Visible = False
Next p
For Each p In TabCtl_2.Pages
p.Visible = False
Next p
'Make invisible unless selected
If Combo1.Value = "Supercharged" Then
TabCtl_1.Visible = True
TabCtl_2.Visible = False
ElseIf Combo1.Value = "Misc" Then
TabCtl_2.Visible = True
TabCtl_1.Visible = False
Else
TabCtl_1.Visible = False
TabCtl_2.Visible = False
End If
'Turn on selected page
Select Case Combo1.Value
Case "Bolt Ons"
Combo2.Value = ""
Combo2.Visible = True
ComboBox2_Label.Caption = "Bolt Ons"
Me.Combo2.RowSource = "Intake;Headers;Exhaust"
Case "Internals"
Combo2.Value = ""
Combo2.Visible = True
ComboBox2_Label.Caption = "Internals"
Me.Combo2.RowSource = "Pistons;Rods;Crankshaft"
Case "Ignition"
Combo2.Value = ""
Combo2.Visible = True
ComboBox2_Label.Caption = "Ignition"
Me.Combo2.RowSource = "Spark Plaugs;Coils;Wires"
Case "Supercharged"
Page4.Visible = True
Combo2.Visible = False
Case "Misc"
Page8.Visible = True
Combo2.Visible = False
End Select
End Sub
Private Sub Combo2_Change()
' Turn off pages in top tab
For Each p In TabCtl_1.Pages
p.Visible = False
Next p
' Turn off pages in bottom tab
For Each p In TabCtl_2.Pages
p.Visible = False
Next p
'Turn on/off top tab border
If Combo2.Value = "Intake" Or Combo2.Value = "Headers" Or Combo2.Value = "Exhaust" Then
TabCtl_1.Visible = True
Else
TabCtl_1.Visible = False
End If
'Turn on/off bottom tab border
If Combo2.Value = "Pistons" Or Combo2.Value = "Rods" Or Combo2.Value = "Crankshaft" Then
TabCtl_2.Visible = True
Else
TabCtl_2.Visible = False
End If
'Turn on selected page
Select Case Combo2.Value
Case "Intake"
Page1.Visible = True
Case "Headers"
Page2.Visible = True
Case "Exhaust"
Page3.Visible = True
Case "Pistons"
Page5.Visible = True
Case "Rods"
Page6.Visible = True
Case "Crankshaft"
Page7.Visible = True
End Select
End Sub