Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211

    Locate Custom Ribbon if it Exists

    Hello,



    I have a couple of databases that I'm using custom ribbons for. I've created a module containing all the global ribbon variables and functionality. Here is what happens when the ribbon is instantiated:
    Code:
    Public Sub OnRibbonLoad(ByVal ribbon As IRibbonUI)
         Set gRibbon = ribbon
        gRibbon.InvalidateControl ("menu")
    End Sub
    Then various pieces of code have methods to invalidate the ribbon controls:
    Code:
    If Not gRibbon Is Nothing Then
        gRibbon.InvalidateControl "{RibbonID}"
    End If
    So I notice when I've been modifying the application, and it's been open a long time, sometimes the gRibbon variable loses its value, so none of the Invalidate code ever gets run.

    I know if I close and re-open the database, everything runs fine. I'm worried that if my customer has the database open for a long time, the same thing will happen in production.

    Rather than having to train them to close and reopen the database, is there a way to refresh the global object? I've tried playing with CommandBars collection, and that seems to work, but I'm worried about that type of object being deprecated, as I've seen some things about that in the help documents.

    Is there an easy way to locate my custom ribbon after the fact and fix the problem as needed? For example:
    Code:
    If gRibbon Is Nothing Then
        'Do this to reinstantiate the object
    End If
    Thanks...

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Why would global lose value just because db is open a long time? That should not happen.

    Why are parts of ribbon 'invalidated' in separate code procs?

    Did you try a Set line in the Is Nothing test proc?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    So I notice when I've been modifying the application, and it's been open a long time
    Is this only occurring during development?
    Are you encountering any errors during dev?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  4. #4
    DittoBird's Avatar
    DittoBird is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2015
    Location
    Newfoundland & Labrador, Canada
    Posts
    59
    If your application throws an unhandled error, variables are reset. Do you include error handling in all your procedures?

    Something as simple as the following helps a lot in 1) preventing loss of variables, and 2) the msgbox title (or in the body of the message or both) helps you narrow down where the error is manifesting itself:

    Code:
    Private Sub txtSearchCombo_Change()
        On Error GoTo Err_Proc
        Me.cboTest.Requery
    Exit_Proc:
        Exit Sub
    Err_Proc:
        Select Case Err.Number
            Case Else
                MsgBox "Access Error " & Err.Number & " " & Err.Description, vbCritical, "Error txtSearchCombo_Change", Err.HelpFile, Err.HelpContext
                Resume Exit_Proc
        End Select
    End Sub

    --
    Tim

  5. #5
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Thanks June7. Don't know why a global object loses its value after a while. You're right, should have its value always.
    Ribbon controls are invalidated as they are used. Example: Ribbon button to open a form. In form open event, I invalidate that button so somebody doesn't open the same form again. I also invalidate the quit button at same time. In Form_Close event, I invalidate those same buttons, which causes them to be enabled now that the form is closed. Requires I keep a list of open objects, which is checked in the invalidate code.

    I will try a Set line. That's the reason for this post. What to I set gRibbon to if it's no longer having its value? During the onRibbonLoad event, the actual ribbon object is passed in, and that's where I set gRibbon value the first time.

  6. #6
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Thanks moke123. Can't really answer, it's only been development so far for this feature. No other errors are occurring, however.

  7. #7
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Thanks for the suggestion, Tim. I usually have error trapping, but not always. Are you saying ANY unhandled error anywhere causes objects and global variables to lose their values?
    At this point, I'm not sure it's due to errors. If I see a ribbon button not properly enabled or disabled, I go to Immediate window and query whether gRibbon has a value. That's how I found out the issue.

    Now, I just want to know how I re-set that global variable. How do I find the ribbon objet itself? As mentioned earlier, I think I can find it in the CommandBars collection, but I'm not confident that that collection won't be deprecated in the future.

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    No other errors are occurring, however.
    Perhaps somewhere you have On Error Resume Next, which is likely to suppress an error message but not the effects of the error. That error handler should only be used in very specific situations. Or perhaps you've used On Error GoTo 0, which disables any active handler.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    I recommend using error handling in ALL procedures.
    However, I disagree with Tim. Only very rarely will an unhandled error cause a global variable to lose its value.

    One thing you should check. In the VBE go to Tools...Options ...and click the General tab
    Make sure error trapping is set to Break on Unhandled Errors and NOT Break On All Errors

    Click image for larger version. 

Name:	Capture.PNG 
Views:	20 
Size:	15.3 KB 
ID:	43517
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  10. #10
    DittoBird's Avatar
    DittoBird is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2015
    Location
    Newfoundland & Labrador, Canada
    Posts
    59
    Quote Originally Posted by isladogs View Post
    I recommend using error handling in ALL procedures.
    However, I disagree with Tim. Only very rarely will an unhandled error cause a global variable to lose its value.
    Sorry, RMittelman, given my nearly 6 year absence from Access, Colin is more likely correct.

    Colin, I could be wrong, but it was the wisdom of the day in A2003. Or am I remembering incorrectly? ISTR emphasizing the importance of error handling on CDMA for retention of variables to newcomers. Or was/is that more for form and module variables? It definitely affected my applications and I was religious about error handling as a result.

    All the best,
    --
    Tim

  11. #11
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Hi Tim
    I've answered in your new thread on the subject at https://utteraccess.com/topics/2059966/posts/2768629
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  12. #12
    DittoBird's Avatar
    DittoBird is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Apr 2015
    Location
    Newfoundland & Labrador, Canada
    Posts
    59
    Thanks, Colin

    Quote Originally Posted by DittoBird View Post
    Sorry, RMittelman, given my nearly 6 year absence from Access, Colin is more likely correct.

    Colin, I could be wrong, but it was the wisdom of the day in A2003. Or am I remembering incorrectly? ISTR emphasizing the importance of error handling on CDMA for retention of variables to newcomers. Or was/is that more for form and module variables? It definitely affected my applications and I was religious about error handling as a result.

    All the best,
    --
    Tim

  13. #13
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    No problem
    BTW - I had no problem working out what ISTR meant but CDMA defeated me....
    BFN
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  14. #14
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Thanks for the answers everyone. I'm a bit confused by what is meant by global variables lose their value on unhandled errors.

    I have a Public variable called gRibbon in a module. Does that make it a global variable? Not sure what goes on during unhandled errors, somewhere in application. Are we saying anywhere in the application code that an unhandled error occurs can cause any or all of the public variables to lose their value? Or are we talking about unhandled errors that specifically occur in code mentioning or using my public variable? I'm presuming that using On Error Resume Next does NOT cause an "unhandled error", right?

    All this notwithstanding, does anyone have a clue how I can reinstantiate my gRibbon object? Maybe reinstantiate is the wrong word. The custom ribbon is still there, I just have no object variable that points to it (after the unhandled error or whatever occurs). The onRibbonLoad event only occurs once, right? And that is the event that actually knows about the ribbon, right? Any other way to "get" that custom ribbon object? If so, then I can "fix" the problem on-the-fly until I can discover why the variable is losing its value.

    Thanks...

  15. #15
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    On Error Resume Next does NOT cause an "unhandled error", right?
    I would agree with that from a purely semantic point of view simply because it means that one has chosen to handle the error by doing nothing. Let's say that what it means that control passes to the next line of code without doing anything about the error that has been raised. Quite certain that if you start code and check the err object error number it will be 0. Execute On Error Resume Next then set a long type of variable value to =5/0. When you execute that line and then the next, no error message will be given but the err.number will not be 0 anymore. So what I was getting at is that you could have been raising an error that caused your global to be lost and then later you were invoking it. Since there are Class modules and code modules, the answer to your other question is "maybe". A form/report module is a type of class module and in those, public variables are only visible to the class and are usually created by declaring at the top (before any code) and not within the code itself. In fact, it is not necessary to define such a variable as public (to the class). Variables declared as public in a standard code module are "global" in the sense that they are visible throughout the project.

    I will defer to others regarding whether or not they are lost in any particular version. It has been my experience that a global variable that is a property of a custom class (e.g. a custom object) was always lost when errors were raised. In every case I had to add an IF statement before trying to use the variable to test. If it was invalid I had to run the property let and property get statements again. So I'm saying that I have had global variables tank on me lots of times even though I had lots of error handling.

    I'd be tempted copy the db and set the option to break on all errors and see what happens. For each break on an unrelated procedure, I'd rem out the cause, check the global and keep trying to see if I could raise an error that causes the global to be lost. However, I'd only do that if I was sure that there was no error handling that I've written or circumvented that could be the cause. I suppose that you could also post a compacted and zipped db copy so that it could be tested in various Access versions.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 03-25-2015, 10:28 PM
  2. Custom Ribbon
    By June7 in forum Access
    Replies: 13
    Last Post: 08-01-2014, 02:44 AM
  3. Custom Ribbon question
    By croydon in forum Access
    Replies: 1
    Last Post: 12-13-2013, 10:34 AM
  4. Custom Button in Ribbon
    By chriscardwell06 in forum Access
    Replies: 3
    Last Post: 12-12-2013, 08:09 AM
  5. Custom Ribbon
    By nkuebelbeck in forum Programming
    Replies: 5
    Last Post: 08-25-2011, 11:55 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums