Multiple conditions on combo box to show different forms

  • Follow


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!!!
0
Reply Utf 12/8/2009 7:53:02 PM

cynteeuh wrote:

>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
-- 
Marsh
MVP [MS Access]
0
Reply Marshall 12/8/2009 9:06:48 PM

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





"cynteeuh" wrote:

> 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!!!
0
Reply Utf 12/9/2009 10:33:04 PM

2 Replies
700 Views

(page loaded in 0.191 seconds)


Reply: