Solved

Using Commandbars.Findcontrol - recognising if not found.

Posted on 2009-05-18
4
251 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
4 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
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 - Access MVP) 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now