Solved

Using Commandbars.Findcontrol - recognising if not found.

Posted on 2009-05-18
4
299 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 84
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

735 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