If ElseIf Question

SmartCarFun

Registered User.
Local time
Today, 20:11
Joined
Feb 17, 2012
Messages
25
Hi,
I have 5 subforms and depending on selection of field [ReturnType] I need to show a subform....

I started with

Code:
Private Sub ReturnType_AfterUpdate()
'After Update of checkbox
'Check if Active checkbox is selected
'then show or hide subform
If Me.ReturnType = "Remittance" Then
Me.Sub_REMIT_Payments.Visible = True
Me.Sub_Returns_F_Clearance.Visible = False
Me.Sub_Returns_F_IHCC.Visible = False
Me.Sub_Returns_F_Reversal.Visible = False
Me.Sub_Returns_F_WriteOff.Visible = False

ElseIf Me.ReturnType = "Clearance" Then
Me.Sub_REMIT_Payments.Visible = False
Me.Sub_Returns_F_Clearance.Visible = True
Me.Sub_Returns_F_IHCC.Visible = False
Me.Sub_Returns_F_Reversal.Visible = False
Me.Sub_Returns_F_WriteOff.Visible = False

ElseIf Me.ReturnType = "IHCC" Then
Me.Sub_REMIT_Payments.Visible = False
Me.Sub_Returns_F_Clearance.Visible = False
Me.Sub_Returns_F_IHCC.Visible = True
Me.Sub_Returns_F_Reversal.Visible = False
Me.Sub_Returns_F_WriteOff.Visible = False

ElseIf Me.ReturnType = "Reversal" Then
Me.Sub_REMIT_Payments.Visible = False
Me.Sub_Returns_F_Clearance.Visible = False
Me.Sub_Returns_F_IHCC.Visible = False
Me.Sub_Returns_F_Reversal.Visible = True
Me.Sub_Returns_F_WriteOff.Visible = False

ElseIf Me.ReturnType = "WriteOff" Then
Me.Sub_REMIT_Payments.Visible = False
Me.Sub_Returns_F_Clearance.Visible = False
Me.Sub_Returns_F_IHCC.Visible = False
Me.Sub_Returns_F_Reversal.Visible = False
Me.Sub_Returns_F_WriteOff.Visible = True

Else
Me.Sub_REMIT_Payments.Visible = False
Me.Sub_Returns_F_Clearance.Visible = False
Me.Sub_Returns_F_IHCC.Visible = False
Me.Sub_Returns_F_Reversal.Visible = False
Me.Sub_Returns_F_WriteOff.Visible = False


End If
End Sub

But then decide to set all subforms to Visible NO and try it this way....

Code:
Private Sub ReturnType_AfterUpdate()
'After Update of checkbox
'Check if Active checkbox is selected
'then show or hide subform
If Me.ReturnType = "Remittance" Then
Me.Sub_REMIT_Payments.Visible = True

ElseIf Me.ReturnType = "Clearance" Then
Me.Sub_Returns_F_Clearance.Visible = True

ElseIf Me.ReturnType = "IHCC" Then
Me.Sub_Returns_F_IHCC.Visible = True

ElseIf Me.ReturnType = "Reversal" Then
Me.Sub_Returns_F_Reversal.Visible = True

Else
Me.Sub_Returns_F_WriteOff.Visible = True

End If
End Sub

I get a compile error, can anyone see anything obviously wrong with what I'm trying to do?

Thanks All
 
where exactly do you get the error ?

Why not using Select case? This is the obvious place to use it
 
One of my subforms was corrupt, the first code work the second holds the subform in visible state so can't see what's under it....

How would I use select?
 
Code:
Select case Me.ReturnType
  case "Remittance"
    ... Do something
  case "Clearance"
   ... Do something different
  ....
  Case else
  MsgBox "I have no idea what to do"
end select
case else is not required, it's only to make sure nothing is forgotten

In you case if you set the selections as your sub forms names you can have another style of code:
Code:
dim strSubFormName as string
 
Me.Sub_REMIT_Payments.Visible = False
Me.Sub_Returns_F_Clearance.Visible = False
Me.Sub_Returns_F_IHCC.Visible = False
Me.Sub_Returns_F_Reversal.Visible = False
Me.Sub_Returns_F_WriteOff.Visible = False

strSubFormName = Me.ReturnType
Me(strSubFormName).Visible = true
 

Users who are viewing this thread

Back
Top Bottom