#1
|
|||
|
|||
Removing controls from userform
My program is about to complete but there is a minor problem.
I have a combo box and dynamically created checkboxes. When the combo box item changes the no. of checkboxes that will be displaced will change, what I want is when combo box item changes all the controls on the userform should be automatically removed. In short, I want to remove the controls of userform on combo box change. I am using the below code but its giving me an "Invalid Argument" error. Code:
Public Sub chkbox_remover(loop_ulimit As Integer, ctrl_name As String) Dim looper As Integer If eqp_count > 0 Then If loop_ulimit > 0 Then For looper = 1 To loop_ulimit frmEqpDetails.Controls.Remove ctrl_name & looper Next looper End If End If End Sub |
#2
|
||||
|
||||
What are the values of ctrl_name and looper when it fails?
|
#3
|
|||
|
|||
The values of ctrl_name is "chckbox" and looper is "1" when it fails.
Means chckbox1 when it fails. |
#4
|
||||
|
||||
That should work as long as the control name is correct and the control was created at run time. How and when did you create it?
|
#5
|
|||
|
|||
Hiii,
Please find the attached file for your understanding. When you select the item from combo box at that time it will work good till save button. After that if you want to use the program again then it shows the error. "Invalid Argument" Just try you will get to know what am I saying. |
#6
|
||||
|
||||
That's because you are trying to delete controls that aren't there. The Save code needs to reset your counter variables to 0 so that the change event of the combobox doesn't try and delete nonexistent controls.
|
#7
|
|||
|
|||
U r a genius. It worked.
Thanks a lot. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
UserForm to Add XML Mapped Content Controls | DocTeam10 | Word VBA | 0 | 10-08-2015 08:27 AM |
VBA Code in a UserForm module to delete a Command Button which opens the userform | Simoninparis | Word VBA | 2 | 09-21-2014 03:50 AM |
Is it possible to take an input from a UserForm in one document to a UserForm in a do | BoringDavid | Word VBA | 5 | 05-09-2014 09:08 AM |
Content Controls | Sammie0Sue | Word | 6 | 11-06-2013 10:56 PM |
Can't Download Controls | BillTheAdmin | Project | 2 | 12-05-2005 10:20 AM |