Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Ifs make different controls visible 1

Status
Not open for further replies.

BrianLe

Programmer
Feb 19, 2002
229
US
I have a form with many textboxes and a few listboxes. I want to hide specific textboxes depending on what is selected in the listbox. I've tried the following, but it only seems to work for ProcessID = 3.

Code:
Private Sub lbxProcessID_AfterUpdate()

If Me![lbxProcessID] = 1 Then
     
      Me!lbxTrainOrderID.Visible = False
      Me!tbxPileAdjustment.Visible = False
 
 End If
 
 If Me![lbxProcessID] = 2 Then
           
      Me!tbxPileAdjustment.Visible = False
 
 End If

    If Me![lbxProcessID] = 3 Then
 
      Me!lbxTrainOrderID.Visible = False
   
Else
   
      Me!lbxTrainOrderID.Visible = True
      Me!tbxPileAdjustment.Visible = True
      Me!tbxStackingTubeAdjustment.Visible = True
      
   End If
      
End Sub

With my code none of the textboxes are hidden for ProcessID =1 or 2, but they should be hidden.

Any suggestions?

Thanks,

Brian

 
That is because the final If is overriding the other two. I think you would be better with Select Case:

Code:
Private Sub lbxProcessID_AfterUpdate()

Select Case Me![lbxProcessID] 
   Case 1
     
      Me!lbxTrainOrderID.Visible = False
      Me!tbxPileAdjustment.Visible = False
 
   Case 2 
           
      Me!tbxPileAdjustment.Visible = False
 
   Case 3 
 
      Me!lbxTrainOrderID.Visible = False
   
   CaseElse
   
      Me!lbxTrainOrderID.Visible = True
      Me!tbxPileAdjustment.Visible = True
      Me!tbxStackingTubeAdjustment.Visible = True
      
End Select
      
End Sub
 
Remou,

That works good as long as the correct ProcessID is selected. If the wrong one is selected, and then the correct one is selected, the controls that were originally hidden do not reappear.

Thanks,

Brian
 
Remou,

I figured out how to solve my problem. In each case, I put in code to make the controls that were set to visible = false by the other cases to visible = true.

Now I have,

Code:
Private Sub lbxProcessID_AfterUpdate()

Select Case Me![lbxProcessID]
   Case 1
     
      Me!lbxTrainOrderID.Visible = False
      Me!tbxPileAdjustment.Visible = False
      Me!tbxStackingTubeAdjustment.Visible = True
 
   Case 2
           
      Me!tbxPileAdjustment.Visible = False
      Me!lbxTrainOrderID.Visible = True
      Me!tbxStackingTubeAdjustment.Visible = True
 
   Case 3
 
      Me!lbxTrainOrderID.Visible = False
      Me!tbxPileAdjustment.Visible = True
      Me!tbxStackingTubeAdjustment.Visible = True
   
   Case Else
   
      Me!lbxTrainOrderID.Visible = True
      Me!tbxPileAdjustment.Visible = True
      Me!tbxStackingTubeAdjustment.Visible = True
      
End Select
      
End Sub

Thanks again,

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top