• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

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.

0
stephenlecomptejr
Asked:
stephenlecomptejr
  • 4
  • 2
  • 2
  • +1
1 Solution
 
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
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now