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

Confirm if controls exists on excel userform

Status
Not open for further replies.

badscottish

Programmer
Feb 6, 2007
3
GB
Hello all,

Is there a simple way to see if a control (e.g. textbox) actually exists on a userform? I'm looping through controls and one of them does not exist: Textbox1, Textbox2, Textbox4. I want to work out before it throws an error if Textbox3 exists. me.control("Textbox3").Exist = true ??? and if not do something else...

Please help, spent days trying to do this...
 
Something like this ?
Dim ExistsControl As Boolean, strControl As String
strControl = "Textbox3"
On Error Resume Next
ExistsControl = CBool(UCase(Me.Controls(strControl).Name) = UCase(strControl))
On Error GoTo 0

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PH!

Thanks for this...

I tried it, but no success. Where we declare strControls it is always going to equal itself. Have I missed an obvious point to this solution or do I need more coffee?

ExistsControl = CBool(UCase(Me.Controls(strControl).Name) = UCase(strControl))

Cheers...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top