Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 348
  • Last Modified:

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).
0
donhannam
Asked:
donhannam
1 Solution
 
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
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
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
 
donhannamAuthor Commented:
Thanks that is what I was afer - I had tried = nothing rather than is nothing.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now