can't run the macro or callback function 'GetEnabled (1 Viewer)

AlexRigholt

Registered User.
Local time
Today, 14:39
Joined
Nov 14, 2008
Messages
36
Hi,
I'm using Access 2010. In accdb all works. In accde I get:

can't run the macro or callback function 'GetEnabled'.
Make sure the macro or function exists and takes the correct parameters.
I click OK six times to get rid of the error message, and after that icons on the custom ribbon can be enabled and disabled.
I have de-compiled and compiled code.

Why would it work in accdb and not in accde?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:39
Joined
Oct 29, 2018
Messages
21,357
Hi. You may have to post the relevant XML and callback code to give us an idea what could be wrong, if any, with it/them.
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 07:39
Joined
Apr 27, 2015
Messages
6,280
I just finished learning about the Custom Ribbon and XML so I am no expert. If, as you say, it runs perfectly in the accdb format but not the .accde, I am at a loss.

For S&G, have you tried converting the .accde back to .accdb to see if it works?
 

missinglinq

AWF VIP
Local time
Today, 07:39
Joined
Jun 20, 2003
Messages
6,423
There's no way to convert a .accde file back to a .accdb file...that's why it's important to save your .accdb file after converting it.

WE really need to see all relevant code, as theDBguy said. The point of converting the file to a .accde file is to 'lock down' the database so that end users can't see code or make design changes to it...and that may be what the code is trying to do.

Linq ;0)>
 

AlexRigholt

Registered User.
Local time
Today, 14:39
Joined
Nov 14, 2008
Messages
36
I removed lots of tabs from the xml. When I add the second button (that calls GetEnabled) then the error occurs.

Code:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="onRibbonLoad">

    <commands>
        <command idMso="Help" enabled="false"/>
        <command idMso="WindowClose" enabled="false"/>
        <command idMso="WindowRestore" enabled="true"/>
        <command idMso="WindowMinimize" enabled="true"/>
        <command idMso="ApplicationOptionsDialog" enabled="false"/>
        <command idMso="FileExit" enabled="false"/>
    </commands>

    <ribbon startFromScratch="true">

        <officeMenu>
            <button idMso="FileOpenDatabase" visible="false" />
            <button idMso="FileNewDatabase" visible="false" />
            <button idMso="FileCloseDatabase" visible="false"/>
            <splitButton idMso="FileSaveAsMenuAccess" visible="false" />
        </officeMenu>

       <qat>
         <documentControls>
         <button idMso="Copy"/>
         <button idMso="Paste"/>
         <button idMso="PrintDialogAccess"/>
         </documentControls>
      </qat>

     <tabs>
            <tab id="tabHome" label="Home">
               <group id="grpFile" label="File"  visible="true">
                    <button id="Home_File_OpenButton" label="Open Data File - F5" imageMso="FileOpen" 
                         screentip="Open a PayEasy data file." size="large" onAction="OnActionButton" /> 
                    <button id="Home_File_BackupButton" label="Back up - F4" imageMso="FileBackupDatabase" 
                         screentip="Make a backup copy of the data file." size="large" onAction="OnActionButton" getEnabled="GetEnabled" />
                </group>
            </tab>


        </tabs>
    </ribbon>

</customUI>
 
Last edited by a moderator:

theDBguy

I’m here to help
Staff member
Local time
Today, 04:39
Joined
Oct 29, 2018
Messages
21,357
Hi. Thanks for posting your ribbon xml. Please don’t forget to post the callback code as well.
 

isladogs

MVP / VIP
Local time
Today, 11:39
Joined
Jan 14, 2017
Messages
18,186
Hi Alex
I fixed the code tags to make your code easier to read.
To use code tags, click the # button on the toolbar and paste between the code and /code tags that appear ... or you can type the tags … in square brackets... manually
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:39
Joined
May 7, 2009
Messages
19,169
on your accdb, goto Options->Client Settings.
tick "show add-in user interface errors".
close and re-open the accdb.
did you see any errors, regarding the ribbon.
 

AlexRigholt

Registered User.
Local time
Today, 14:39
Joined
Nov 14, 2008
Messages
36
Thanks very much for your replies! Had a busy week so am late responding.


- I selected "show add-in user interface errors" but got no error.
- Attached the callback code.


I'll now remove all buttons but the first two, and remove all callback code except that for the first two buttons. If that works, then I'll add back stuff until it gives errors.
 

Attachments

  • CallbackCode.txt
    22.5 KB · Views: 164

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:39
Joined
May 7, 2009
Messages
19,169
for a test, add a variable to your Sub Enabled:

Code:
Public Sub GetEnabled(ctl As IRibbonControl, ByRef Enabled)
    Dim varValue  As Variant    
    Enabled = True
replace the Enabled from your Select Case with varValue.
before the End of the Sub, test the value of varValue:
Code:
…
...
If IsNull(varValue) Then 
   Enabled = False
End If
End Sub
 

AlexRigholt

Registered User.
Local time
Today, 14:39
Joined
Nov 14, 2008
Messages
36
Hi Arnelgp,


'replace the Enabled from your Select Case with varValue.' You mean I should use
 

AlexRigholt

Registered User.
Local time
Today, 14:39
Joined
Nov 14, 2008
Messages
36
In the meantime i have found out that replacing the dlookup with a global variable will work. This means that i have to set about 50 global variables before loading the ribbon.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:39
Joined
May 7, 2009
Messages
19,169
Code:
...
Select Case ctl.id
' Tab: Home
' Group: File
    Case "Home_File_BackupButton"
        varValue = DLookup(gstrLevel, "Rights", "long='Back up'")
…
…
 

AlexRigholt

Registered User.
Local time
Today, 14:39
Joined
Nov 14, 2008
Messages
36
Hello arnelgp, I put in your code and got the same result: ok in accdb, errors in accde.
It looks like a timing issue.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:39
Joined
May 7, 2009
Messages
19,169
then you have to settle for global variable.
use TempVars instead. they won't easily get destroyed when a runtime error occurs.

btw I see you have gstrLevel variable in your dlookup.
I assume it is the name of the field in your table, since that is the syntax of dlookup.
does it returns a Boolean (true or false, -1 or 0).
because you are assigning it to Enabled.

is the sub declaration correct:

Public Sub GetEnabled(ctl As IRibbonControl, ByRef Enabled)

or do you need to specifically tell that Enabled is a Boolean?

Public Sub GetEnabled(ctl As IRibbonControl, ByRef Enabled As Boolean)

on the ribbon I created Enabled is in lower case, does that make any difference?
also ctl in my ribbon is control:
Code:
Sub GetEnabled([COLOR="Red"]control[/COLOR] As IRibbonControl, ByRef enabled)
' Callbackname in XML File "getEnabled"

' To set the property "enabled" to a Ribbon Control
' For further information see: http://www.accessribbon.de/en/index.php?Downloads:12
' Setzen der Enabled Eigenschaft eines Ribbon Controls
' Weitere Informationen: http://www.accessribbon.de/index.php?Downloads:12

      Select Case control.ID

      Case Else
            enabled = True

      End Select

End Sub
 
Last edited:

AlexRigholt

Registered User.
Local time
Today, 14:39
Joined
Nov 14, 2008
Messages
36
Thanks for looking into this, I found the problem.
When running the callback code global variable gstrLevel had been set in accdb, and apparently not in yet in accde. After setting it at the very beginning there are no more errors.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:39
Joined
May 7, 2009
Messages
19,169
good for you then, now gstrLevel is no more an orphan!
 

Users who are viewing this thread

Top Bottom