Using Commandbars.Findcontrol - recognising if not found.

I am using the following to set some menu items to not visible:-
Dim cbc As Object
Set cbc = CommandBars.FindControl(, , 10)
cbc.Visible = False
Set cbc = Nothing

If there is no menu item with tag 10 then I get an error "Obect variable not set"

Is there a way that I can check to see it the findcontrol found anything and if not do nothing
Something like
If cbc <> nothing then (this doesn't work).
donhannamAsked:
Who is Participating?
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Connect With a Mentor Database ArchitectCommented:
You can check for Is Nothing to prevent the error:

Dim cbc As Object
Set cbc = CommandBars.FindControl(, , 999)
If Not cbc Is Nothing Then cbc.Visible = False
Set cbc = Nothing

mx
0
 
Rey Obrero (Capricorn1)Commented:
try ignoring the error

On error resume next   '<<< Add this line
Dim cbc As Object
Set cbc = CommandBars.FindControl(, , 10)
cbc.Visible = False
Set cbc = Nothing
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
0
 
donhannamAuthor Commented:
Thanks that is what I was afer - I had tried = nothing rather than is nothing.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.