How to check first for an existence of an Access toolbar before running DoCmd.ShowToolbar "Logger", acToolbarYes

I've got several toolbars that I turn on....
but I need to check to see if they exist first because I"ll get an error: 2094 Microsoft Office Access can't find toolbar.
I want to avoid using the Error Handling to bypass this error and first check to see if it exists?

Any ideas?

Thank you, Stephen.

LVL 1
stephenlecomptejrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Leigh PurvisDatabase DeveloperCommented:
Hi

Why do you want to avoid using error handling?
If I were to write a function that returned the existance of a tollbar name passed to it then guess how I'd do that?
Capture the error if it didn't exist.

Function fToolBarExists(strName) As Boolean
On Error Resume Next
   
    Dim strRetName As String
   
    strRetName = CommandBars(strName).Name
   
    If Not err Then
        fToolBarExists = True
    End If
   
End Function

But if you want an alternative...

Function fToolBarExists(strName) As Boolean
On Error Resume Next
   
    Dim strRetName As String
    Dim intCount As Integer
    Dim intLoop As Integer
   
    intCount = CommandBars.Count
   
    For intLoop = 1 To intCount
        If CommandBars(intLoop).Name = strName Then
            fToolBarExists = True
            Exit For
        End If
    Next
   
End Function

But that should be far less efficient!

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
flavoCommented:
How about a function like this?

Function showToolbar(s As String)

    Dim c As Object
   
    For Each c In Application.CommandBars
        If c.Name = s Then
            DoCmd.showToolbar s, acToolbarYes
        End If
    Next

End Function

Dave
0
flavoCommented:
<Well I certainly was a little slow there :P >

Dave
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Leigh PurvisDatabase DeveloperCommented:
< Did your butler distract you with your latest riverside cold pint? ;-) >
0
stephenlecomptejrAuthor Commented:
LPurvis - why is it less efficient - is it the fact that you're looping all through the toolbars?

is it not best not to have any errors thrown in the call stack - which is worst?
0
Leigh PurvisDatabase DeveloperCommented:
Yep - you'd be aghast at the number that there are.
(Well perhaps not - but there are lots, 182 in the first db I grabbed :-)

Errors aren't "thrown in the call stack" if they're properly dealt with.
Unhandled errors will travel back up the stack - but it's nothing to be afriad of from properly handled errors within a self contained function.
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Agree with Leigh - using the Errors collection and Err object in the manner indicated are commonly used programming techniques and have no impact on the performance or integrity of the application (used properly, of course).
0
stephenlecomptejrAuthor Commented:
Thanks tremondously!
0
Leigh PurvisDatabase DeveloperCommented:
Welcome :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

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.