Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 34
  1. #16
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Quote Originally Posted by RMittelman View Post
    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...
    Global / public variables are essentially the same thing. These should only be declared in a standard/class module - not a form/report module.



    Variables in forms/reports are specific to that object so should be Private. Use Dim to declare these

    Agree with Micron's comments regarding On Error Resume Next. I also recommend avoiding its use in your apps.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  2. #17
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    Global / public variables are essentially the same thing. These should only be declared in a standard/class module - not a form/report module.
    Not sure I agree with that statement. A variable declared at the top of the module is visible to the whole module whether you specifically declare it as Public or not. They probably should have kept a distinction between global and public so that a distinction between project and module scope could be better understood. Anyway, some M$ reading on the subject
    https://docs.microsoft.com/en-us/off...ring-variables
    wherein it states
    Public variables can be used in any procedures in the project.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #18
    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
    No problem
    BTW - I had no problem working out what ISTR meant but CDMA defeated me....
    BFN
    Sorry, Colin, Comp.Databases.ms-access was (maybe still is?) a very big news group on the usenet system. There were a lot of folks who helped steer me in good directions and came to my rescue when I was asking about inadvisable things. I started using usenet in 1994 and kept up with it until the mid-2000s when web based forums seemed to take over.
    --
    Tim

  4. #19
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Quote Originally Posted by Micron View Post
    Not sure I agree with that statement. A variable declared at the top of the module is visible to the whole module whether you specifically declare it as Public or not. They probably should have kept a distinction between global and public so that a distinction between project and module scope could be better understood. Anyway, some M$ reading on the subject
    https://docs.microsoft.com/en-us/off...ring-variables
    wherein it states

    Public variables can be used in any procedures in the project.
    Perhaps my reply wasn't as clear as it should have been
    I agree that a variable declared at the top of a module has scope for the entire module.
    If declared as Public/Global in a standard module the scope is for the whole project.

    If you try to define a Global variable in the declarations section of a form/report module, you will get an error:
    Click image for larger version. 

Name:	Capture.PNG 
Views:	35 
Size:	27.3 KB 
ID:	43525

    However, Access won't object if you call it Public rather than Global! No idea why. In that sense, the two aren't 'essentially the same'
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  5. #20
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Thanks Tim re meaning of CDMA. I never got into Usenet back in the 90s which may explain my ignorance of that acronym
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  6. #21
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    If you try to define a Global variable in the declarations section of a form/report module, you will get an error:
    Probably because the form/report module code is only available when the form/report is loaded, thus can't be 'global'.

  7. #22
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    @isladogs, that's why I don't agree with those who say global and public mean the same thing. It's only true if you use either word in very specific places. IMO scope is a bit difficult for the newbie.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #23
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    This is from an answer at Stackoverflow: https://stackoverflow.com/questions/...0forms%20etc.)

    Dim and Private work the same, though the common convention is to use Private at the module level, and Dim at the Sub/Function level. Public and Global are nearly identical in their function, however Global can only be used in standard modules, whereas Public can be used in all contexts (modules, classes, controls, forms etc.) Global comes from older versions of VB and was likely kept for backwards compatibility, but has been wholly superseded by Public.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  9. #24
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    217
    Thanks again for all the answers. The replies clarifying global vs. public objects are interesting, and I've learned from them. However, they don't address how to restore the global/public variable gRibbon when it's been lost. Granted, this is happening during development, so certain errors are going to come up and maybe destroy the variable. This shouldn't happen in production if the application is coded properly.

    If this does happen, the best thing is to either close and restart the database, or do a compact/repair, which will reload the ribbon and re-establish the global variable. I have a compact/repair button on my custom ribbon, and can instruct customers to use that. I can change the code snippets to pop a message box if gRibbon is nothing, and tell users to click the compact button.

    All that being said, I was able to find this article which demonstrates a technique for saving and restoring the global variable:
    https://www.utteraccess.com/topics/2002191

    Thanks again...

  10. #25
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    Testing is when I lost my variable, which was a custom property of the db user. To make sure it never happened, each time I invoked dbUser.EmplId for example, I tested as in
    If dbUser.EmplID = "" (or something like that) then I re-ran the Property Let and Property Get statements to reinstantiate it. Perhaps you'll have to do something similar. If you showed any code for this I don't recall seeing it so I don't know if a loaded ribbon is one of your db properties or what, but if if is, you could always test and then reset I suppose.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #26
    shcsbaker is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    4
    RMittelman,
    Any chance you have info on the utteraccess article?

    Thanks,
    Kevin

  12. #27
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    217
    Sorry, I don't. Have to search for it. Don't remember details after several years.

  13. #28
    June7's Avatar
    June7 is online now VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Utter Access is dead so thread will likely not be available anywhere.
    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.

  14. #29
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    Quote Originally Posted by June7 View Post
    Utter Access is dead so thread will likely not be available anywhere.
    If you do want to go searching, this would be a start.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  15. #30
    shcsbaker is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    4
    RMittelman - I was hoping you had found a solution to your original question. I did try using the wayback machine, but didn't have any luck. I was thinking about asking Gork or ChatGPT if it's possible to have a self-healing ribbon pointer, but I've learned the "bots" will tell you with certainty how to care for your unicorn, only to tell you 2 hours into the "conversation" unicorns don't exist.

    I'm using vbWatchDog, but somewhere, somehow I have a few customers where the ribbon pointer gets reset to Nothing. Having a self-healing ribbon pointer would be very helpful.

    Is a self-healing ribbon pointer an Access unicorn???

Page 2 of 3 FirstFirst 123 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