[AccessD] Ribbon context

Jim Dettman jimdettman at verizon.net
Tue Jan 25 07:24:54 CST 2022


This is an ad-hoc procedure I use to set various form properties.

Note just before line 90, I was setting OnActivate/OnDeactivate events to =StdFormCT([Form],"OnActivate","")

StdFormCT() is short for "Standard Form Control".   It's part of a set of routines that make-up a framework for forms and controls that I once used

HTH,
Jim.


Function DoAllForms_DesignModeChange() As Integer

        ' This function loops through all Forms

        Dim db As Database
        Dim MyDocument As Document
        Dim frm As Form
        Dim ctrl As Control                                    'Used for controls on form.
        Dim lngI As Long
        Dim intRet As Integer

10      Set db = DBEngine.Workspaces(0).Databases(0)

20      For lngI = 0 To db.Containers("Forms").Documents.count - 1

30        Set MyDocument = db.Containers("Forms").Documents(lngI)
40        Debug.Print " > Document: "; MyDocument.Name;
50        Debug.Print ""


60        If MyDocument.Name = "frmInvoiceList" Then
70          DoCmd.OpenForm (MyDocument.Name), A_DESIGN
80          Set frm = Forms(MyDocument.Name)

            'frm.MaxButton = False
            'frm.ShortcutMenu = False
            'frm.NavigationButtons = False
            'frm.AllowFilters = False

            'frm.HelpFile = "HRAPP.HLP"
            'frm.HelpContextId = 99999

            'intRet = glrChangePermission(1, frm.name, "USERS", DB_SEC_FRMRPT_EXECUTE, True)

            'If Mid$(NZ(Forms(MyDocument.name).OnClose, ""), 1, 4) = "=Std" Then
            '  frm.OnActivate = "=StdFormCT([Form]," & Chr$(34) & "OnActivateForm" & Chr$(34) & "," & Chr$(34) & Chr$(34) & ")"
            '  frm.OnDeactivate = "=StdFormCT([Form]," & Chr$(34) & "OnDeactivateForm" & Chr$(34) & "," & Chr$(34) & Chr$(34) & ")"
            'End If

       Dim str As String
       
90     For Each ctl In frm.Section(1).Controls
       
100      str = Replace(ctl.Tag, "EXPAND:", "EXPAND=")
         
110      ctl.Tag = str
       
120    Next
       
            'For Each ctrl In frm.Controls
            '  If ctrl.Section = acDetail Then
            '    With ctrl
            '      ' Set afterupdate
            '      Select Case .ControlType
            '        Case acText
            '          strCall = "=StdCtrl(" & Chr$(34) & frm.Name & Chr$(34) & "," & Chr$(34) & ctrl.Name & Chr$(34) & "," & Chr$(34) & "MyAfterUpdate" & Chr$(34) & "," & Chr$(34) & Chr$(34) & ")"
            '          ctrl.AfterUpdate = strCall
            '      End Select
            '    End With
            '  End If
            'Next ctrl

130         Set ctrl = Nothing

140         DoCmd.Close A_FORM, (frm.Name), acSaveYes

150         Set frm = Nothing
160       End If
170     Next lngI

180     DoAllForms_DesignModeChange = True

End Function

-----Original Message-----
From: Ryan Wehler 
Sent: Tuesday, January 25, 2022 7:43 AM
To: Access Developers discussion and problem solving <accessd at databaseadvisors.com>
Cc: Jim Dettman <jimdettman at verizon.net>
Subject: Re: [AccessD] Ribbon context

Yes I plan to call a procedure in the form event, I just was looking for a way to do it without modifying a ton of forms. Which is why a class came to mind withevents

> On Jan 25, 2022, at 6:24 AM, Jim Dettman via AccessD <accessd at databaseadvisors.com> wrote:
> 
> Besides inserting code, you can also simply make a call to a standard procedure right from the OnActivate Property of the form.
> 
> Between these two methods, it's easy to hook-up standard behavior without resorting to classes.
> 
> Jim.
> 
> -----Original Message-----
> From: AccessD On Behalf Of Bill Benson
> Sent: Monday, January 24, 2022 10:51 PM
> To: Access Developers discussion and problem solving <accessd at databaseadvisors.com>
> Subject: Re: [AccessD] Ribbon context
> 
> Writing an onActivate event into every form is a walk in the park. Just add
> a reference to
>    Microsoft Visual Basic for Applications Extensibility 5.3.
> 
> 
> Below is a procedure that would add a Form_Activate event to every
> form, check if there is already a line saying Call MyProcedure, if not add
> that line of code before the End Sub. If no Form_Activate, it will add such
> a procedure with that line of code.
> 
> Save your project before running it; and do a Debug.Compile afterwards to
> make sure that nothing went wrong unexpectedly.
> 
> You will have to manually save after the code is checked.
> Note, it is not easy to debug running code that is inserting code lines, so
> test this on a small database or put in a loop controller to perform the
> action on the first N forms, to make sure it works for you.
> 
> Sub PutInOnActivate()
> Const Form_Activate         As String = "Private Sub Form_Activate()"
> Const LINE_LENGTH           As Integer = 27
> 
> Dim vbComp                  As VBIDE.VBComponent
> Dim vbMod                   As VBIDE.CodeModule
> Dim Form                    As Object
> Dim Container               As Object
> Dim strAllForms             As String
> Dim iLine                   As Long
> Dim jLine                   As Long
> Dim strLine                 As String
> Dim strNextLine             As String
> Dim bLineAdded              As Boolean
> 
> For Each Container In CurrentDb.Containers
>    If Container.Name = "Forms" Then
>        Exit For
>    End If
> Next
> 
> For Each Form In Container.Documents
>    strAllForms = strAllForms & "|Form_" & Form.Name
> Next
> If strAllForms <> "" Then
>    strAllForms = strAllForms & "|"
>    For Each vbComp In Application.VBE.VBProjects(1).VBComponents
>        If InStr(strAllForms, "|" & vbComp.Name & "|") > 0 Then
>            With vbComp.CodeModule
>                For iLine = 1 To .CountOfLines
>                    strLine = Trim(.Lines(iLine, 1))
>                    If Left(strLine, LINE_LENGTH) = Form_Activate Then
>                        bLineAdded = False
>                        For jLine = iLine + 1 To .CountOfLines
>                            strNextLine = Trim(.Lines(jLine, 1))
>                            If Left(strNextLine, 7) = "End Sub" Then
>                                .InsertLines jLine, vbTab & "Call
> MyProcedure"
>                                GoTo NextForm
>                            ElseIf Left(strNextLine, Len("Call
> MyProcedure")) = "Call MyProcedure" Then
>                                GoTo NextForm
>                            End If
>                        Next
>                        .InsertLines iLine + 1, vbTab & "Call MyProcedure"
>                        GoTo NextForm
>                    End If
>                Next
>                .InsertLines iLine, "Private Sub Form_Activate()"
>                .InsertLines iLine + 1, vbTab & "Call MyProcedure"
>                .InsertLines iLine + 2, "End Sub"
>            End With
>        End If
> NextForm:
>    Next
> End If
> End Sub
> 
> 
> 
>> On Mon, Jan 24, 2022 at 7:38 PM Ryan W <wrwehler at gmail.com> wrote:
>> 
>> In Access I’m trying to disable some ribbon buttons based on the form in
>> question and permissions to delete records on that form.
>> 
>> I’ve got the getEnabled logic worked out and it disables the delete button
>> on the ribbon when I invalidate the control via the OnActivate event for
>> the form (so it runs again if the form tab is switched back).
>> 
>> My issue is we have hundreds of forms that would need an OnActivate event
>> added so the delete button can be contextually controlled.
>> 
>> 
>> Is there a better way to do this that isn’t a really fast timer event or
>> some sort of class for handling that event on all forms (can you even
>> instantiate a class object on a closed form?)
>> 
>> 
>> 
>> Right now the delete button always shows but the code behind it will not
>> succeed if the back end tables don’t grant the permissions, it would just
>> be nice to sort of give a visual cue that the action isn’t possible.
>> 
>> 
>> Sent from my iPhone
>> --
>> AccessD mailing list
>> AccessD at databaseadvisors.com
>> https://databaseadvisors.com/mailman/listinfo/accessd
>> Website: http://www.databaseadvisors.com
>> 
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com



More information about the AccessD mailing list