Multiple conditions on combo box to show different forms

C

cynteeuh

I have a form with a tab subform. I have the below code in the "on current"
of main form, "after update" of combobox on main form, & "on click" of the
tab where the subform resides. I'm fairly new to coding. I got the working
code from reading the discussion groups.

How would I add an "is null" argument to this code?

Is the "on click" code necessary or am I doing too much?

I want the subform to be blank if the combo box is empty/null (the combo box
does have a default value).

Select Case Me.Type
Case "Private"
Me.Co_Private_Ownership_Subform.Visible = True
Me.Co_Public_Ownership_Subform.Visible = False
Case "Public"
Me.Co_Public_Ownership_Subform.Visible = True
Me.Co_Private_Ownership_Subform.Visible = False
End Select

Thank you for your help!!!
 
M

Marshall Barton

cynteeuh said:
I have a form with a tab subform. I have the below code in the "on current"
of main form, "after update" of combobox on main form, & "on click" of the
tab where the subform resides. I'm fairly new to coding. I got the working
code from reading the discussion groups.

How would I add an "is null" argument to this code?

Is the "on click" code necessary or am I doing too much?

I want the subform to be blank if the combo box is empty/null (the combo box
does have a default value).

Select Case Me.Type
Case "Private"
Me.Co_Private_Ownership_Subform.Visible = True
Me.Co_Public_Ownership_Subform.Visible = False
Case "Public"
Me.Co_Public_Ownership_Subform.Visible = True
Me.Co_Private_Ownership_Subform.Visible = False
End Select

A tab control's Click event is almost worthless. If you
want ot do something when a tab page is selected, then you
need to use the tab control's Change event.

Then Change event happens regardless of the page that was
selected, so you need to use code to figure out which page
was selected. Normally a Select Case statement is used for
this:

Select Case Me.tabcontrolname
Case 0
'code for first page
Case 1
'code for second page
Case 2
. . .
Case Else
MsgBox "no case for " & Me.tabcontrolname
End Select

I think the code for the page where you want to do what you
asked could be something like:

If Me.Type IsNull(Me.Type) Then
'do whatever
ElseIf Me.Type = "Private" Then
Me.Co_Private_Ownership_Subform.Visible = True
Me.Co_Public_Ownership_Subform.Visible = False
ElseIf Me.Type = "Public"
Me.Co_Public_Ownership_Subform.Visible = True
Me.Co_Private_Ownership_Subform.Visible = False
End If
 
B

Brian

You have at least these two options:

1. Explicitly handle the null before the Select Case.

If IsNull(Me.Type) Then
'do something here
Else
Select Case Me.Type
Case "Private"
Me.Co_Private_Ownership_Subform.Visible = True
Me.Co_Public_Ownership_Subform.Visible = False
Case "Public"
Me.Co_Public_Ownership_Subform.Visible = True
Me.Co_Private_Ownership_Subform.Visible = False
End Select
End If

2. Cover the Nulls under a CaseElse as the last element of the Select (i.e.
if case does not match any prior case) - if you are certain Null is the only
other option or are will to treat any other possible options the same as Null:

Select Case Me.Type
Case "Private"
Me.Co_Private_Ownership_Subform.Visible = True
Me.Co_Public_Ownership_Subform.Visible = False
Case "Public"
Me.Co_Public_Ownership_Subform.Visible = True
Me.Co_Private_Ownership_Subform.Visible = False
CaseElse
Me.Co_Public_Ownership_Subform.Visible = False
Me.Co_Private_Ownership_Subform.Visible = False
'or whatever you wanted here
End Select
 

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