Solved

Using Commandbars.Findcontrol - recognising if not found.

Posted on 2009-05-18
4
319 Views
Last Modified: 2013-11-27
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
Comment
Question by:donhannam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24417699
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
 
LVL 85
ID: 24417704
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 500 total points
ID: 24417906
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
 

Author Closing Comment

by:donhannam
ID: 31582824
Thanks that is what I was afer - I had tried = nothing rather than is nothing.
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question