Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-03-2015, 12:21 AM
MOHAMMEDSALMAN MOHAMMEDSALMAN is offline Removing controls from userform Windows 7 64bit Removing controls from userform Office 2007
Novice
Removing controls from userform
 
Join Date: Sep 2015
Location: Mumbai
Posts: 9
MOHAMMEDSALMAN is on a distinguished road
Default 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
In the above code "loop_ulimit" is the maximum number of controls in the userform. "eqp_count" is the count of checkboxes that will appear in userform on combo box selection and "looper" is the no. of controls on userform. I had already defined "eqp_count" as a global variable.
Reply With Quote
  #2  
Old 11-03-2015, 01:35 AM
Debaser's Avatar
Debaser Debaser is offline Removing controls from userform Windows 7 64bit Removing controls from userform Office 2010 32bit
Competent Performer
 
Join Date: Oct 2015
Location: UK
Posts: 221
Debaser will become famous soon enough
Default

What are the values of ctrl_name and looper when it fails?
Reply With Quote
  #3  
Old 11-03-2015, 04:11 AM
MOHAMMEDSALMAN MOHAMMEDSALMAN is offline Removing controls from userform Windows 7 64bit Removing controls from userform Office 2007
Novice
Removing controls from userform
 
Join Date: Sep 2015
Location: Mumbai
Posts: 9
MOHAMMEDSALMAN is on a distinguished road
Default

The values of ctrl_name is "chckbox" and looper is "1" when it fails.

Means chckbox1 when it fails.
Reply With Quote
  #4  
Old 11-03-2015, 04:20 AM
Debaser's Avatar
Debaser Debaser is offline Removing controls from userform Windows 7 64bit Removing controls from userform Office 2010 32bit
Competent Performer
 
Join Date: Oct 2015
Location: UK
Posts: 221
Debaser will become famous soon enough
Default

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?
Reply With Quote
  #5  
Old 11-03-2015, 04:31 AM
MOHAMMEDSALMAN MOHAMMEDSALMAN is offline Removing controls from userform Windows 7 64bit Removing controls from userform Office 2007
Novice
Removing controls from userform
 
Join Date: Sep 2015
Location: Mumbai
Posts: 9
MOHAMMEDSALMAN is on a distinguished road
Default

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.
Attached Files
File Type: xlsm Testing hour tool.xlsm (231.1 KB, 11 views)
Reply With Quote
  #6  
Old 11-03-2015, 04:54 AM
Debaser's Avatar
Debaser Debaser is offline Removing controls from userform Windows 7 64bit Removing controls from userform Office 2010 32bit
Competent Performer
 
Join Date: Oct 2015
Location: UK
Posts: 221
Debaser will become famous soon enough
Default

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.
Reply With Quote
  #7  
Old 11-03-2015, 11:16 PM
MOHAMMEDSALMAN MOHAMMEDSALMAN is offline Removing controls from userform Windows 7 64bit Removing controls from userform Office 2007
Novice
Removing controls from userform
 
Join Date: Sep 2015
Location: Mumbai
Posts: 9
MOHAMMEDSALMAN is on a distinguished road
Default

U r a genius. It worked.

Thanks a lot.
Reply With Quote
Reply



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
Removing controls from userform 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
Removing controls from userform Content Controls Sammie0Sue Word 6 11-06-2013 10:56 PM
Removing controls from userform Can't Download Controls BillTheAdmin Project 2 12-05-2005 10:20 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:44 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft