Compile Error when trying to change Object Visibility

gastoff

New Member
Joined
Oct 13, 2015
Messages
25
I am trying to figure out what is causing my code to derail and could use another set of eyes looking at it.

I have a combobox (cmbEmp1) that is populated with a list of employees.
I have 4 text fields (txtTime1,2,3,4) that have their Visible property set to False upon loading my userform (frmTimeCard).

I am trying to make the text fields visible when any employee in the list is selected, and disappear if the combobox is cleared. Below is the code I have so far:

HTML:
Private Sub cmbEmp1_Change()
Dim index As Integer
Dim x As Long
index = cmbEmp1.ListIndex
For x = 1 To 4
frmTimeCard.Controls("txtTime" & x).Clear
Select Case index
    Case Is = 0
            For x = 1 To 4
            frmTimeCard.Controls("txtTime" & x).Visable = False
            Next x
    Case Else
            For x = 1 To 4
            frmTimeCard.Controls("txtTime" & x).Visable = True
            Next x
End Select    
End Sub

As an amateur at VBA (5 days and counting), I am having trouble debugging.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
And upon reading some other posts, I just stumbled upon how to use the frame object to group things...that could cut out the loop since all the objects are being toggled at once.
 
Upvote 0
I guess you are getting compile errors for:

1. Missing next statement for the first For statement. Add a Next statement after End Select.
2. variable x is used as control variable again inside loops. In inner loops, use different variable names.
 
Upvote 0
I took out the loops and just went with trying to change each object's visibility directly. Still receiving "Compile error. Method or data member not found."

HTML:
Private Sub cmbEmp1_Change()
Dim index As Integer
index = cmbEmp1.ListIndex
Select Case index
    Case Is = 0
          txtTime1.Visable = False
          txtTime2.Visable = False
          txtTime3.Visable = False
          txtTime4.Visable = False
    Case Else
          txtTime1.Visable = False
          txtTime2.Visable = False
          txtTime3.Visable = False
          txtTime4.Visable = False
End Select
End Sub

I know it must be something really simple that I am missing, but I still don't know what is going wrong.
 
Upvote 0

Forum statistics

Threads
1,215,011
Messages
6,122,677
Members
449,092
Latest member
tayo4dgacorbanget

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top