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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Switch Statement and a Counter

Status
Not open for further replies.

leahmw

Technical User
Jul 6, 2007
3
CA
Hi there, I'm very new to Access and I'm trying to use a switch statement...

I have a form entitled contract, and three invisible sets of labels/text boxes/buttons. I have two buttons labelled "Add Occupation", and "Remove Occupation". Add and Remove control the visibility of the sets of controls based on a counter. I have it working, however... there is one slight problem.

Everything works fabulous if I click "Add, Add, Add, Remove, Remove, Remove". However, if I were to click for example, "Add, Add, Remove" I would have to click Remove twice before it makes the appropriate box invisible... I'm sure that it's just something silly I've put in the wrong spot, but it's 8:30AM on a Friday and my brain has had enough, so please help me!!

My code for the two buttons is below: (I've made trades_count a global integer right now, since it's easy to use)

Add Button:

Private Sub bttn_add_occ_Click()

Select Case trades_count
Case Is = 0
Me.lbl_occ_cd0.Visible = True
Me.tb_occ_cd0.Visible = True
Me.lbl_occ_name0.Visible = True
Me.tb_occ_name0.Visible = True
Me.bttn_occ_search0.Visible = True
trades_count = trades_count + 1
Case Is = 1
Me.lbl_occ_cd1.Visible = True
Me.tb_occ_cd1.Visible = True
Me.lbl_occ_name1.Visible = True
Me.tb_occ_name1.Visible = True
Me.bttn_occ_search1.Visible = True
trades_count = trades_count + 1
Case Is = 2
Me.lbl_occ_cd2.Visible = True
Me.tb_occ_cd2.Visible = True
Me.lbl_occ_name2.Visible = True
Me.tb_occ_name2.Visible = True
Me.bttn_occ_search2.Visible = True
End Select

End Sub


Remove Button:

Private Sub bttn_remove_occ_Click()

Select Case trades_count
Case Is = 0
Me.lbl_occ_cd0.Visible = False
Me.tb_occ_cd0.Visible = False
Me.lbl_occ_name0.Visible = False
Me.tb_occ_name0.Visible = False
Me.bttn_occ_search0.Visible = False
Case Is = 1
Me.lbl_occ_cd1.Visible = False
Me.tb_occ_cd1.Visible = False
Me.lbl_occ_name1.Visible = False
Me.tb_occ_name1.Visible = False
Me.bttn_occ_search1.Visible = False
trades_count = trades_count - 1
Case Is = 2
Me.lbl_occ_cd2.Visible = False
Me.tb_occ_cd2.Visible = False
Me.lbl_occ_name2.Visible = False
Me.tb_occ_name2.Visible = False
Me.bttn_occ_search2.Visible = False
trades_count = trades_count - 1
End Select

End Sub

Thanks very much in advance!
 
Perhaps this ?
Code:
Private Sub bttn_add_occ_Click()
Select Case trades_count
    Case Is = 0
        Me.lbl_occ_cd0.Visible = True
        Me.tb_occ_cd0.Visible = True
        Me.lbl_occ_name0.Visible = True
        Me.tb_occ_name0.Visible = True
        Me.bttn_occ_search0.Visible = True
        trades_count = trades_count + 1
    Case Is = 1
        Me.lbl_occ_cd1.Visible = True
        Me.tb_occ_cd1.Visible = True
        Me.lbl_occ_name1.Visible = True
        Me.tb_occ_name1.Visible = True
        Me.bttn_occ_search1.Visible = True
        trades_count = trades_count + 1
    Case Is = 2
        Me.lbl_occ_cd2.Visible = True
        Me.tb_occ_cd2.Visible = True
        Me.lbl_occ_name2.Visible = True
        Me.tb_occ_name2.Visible = True
        Me.bttn_occ_search2.Visible = True
        [!]trades_count = trades_count + 1[/!]
End Select
End Sub

Private Sub bttn_remove_occ_Click()
Select Case trades_count
    Case Is = [!]1[/!]
        Me.lbl_occ_cd0.Visible = False
        Me.tb_occ_cd0.Visible = False
        Me.lbl_occ_name0.Visible = False
        Me.tb_occ_name0.Visible = False
        Me.bttn_occ_search0.Visible = False
        [!]trades_count = trades_count - 1[/!]
    Case Is = [!]2[/!]
        Me.lbl_occ_cd1.Visible = False
        Me.tb_occ_cd1.Visible = False
        Me.lbl_occ_name1.Visible = False
        Me.tb_occ_name1.Visible = False
        Me.bttn_occ_search1.Visible = False
        trades_count = trades_count - 1
    Case Is =[!]3[/!]
        Me.lbl_occ_cd2.Visible = False
        Me.tb_occ_cd2.Visible = False
        Me.lbl_occ_name2.Visible = False
        Me.tb_occ_name2.Visible = False
        Me.bttn_occ_search2.Visible = False
        trades_count = trades_count - 1
End Select
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Wow... one of those "DUH!" moments. Time for a coffee. Or five.

Thanks so much!! I really appreciate it, works fantastic (and prevented a bunch of counter problems down the line...)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top