Form Code for Get My Groups

' ============================================================
' Copyright (c) 2025-2026 Peter Bryant (Corylus Business Systems)
'                    and  Andrew Richards (The IT Service Ltd)
' Part of VBAuth - https://vbauth.com
' Licensed under the MIT Licence - see LICENCE.txt
' This copyright notice must not be removed or altered.
' ============================================================

' ============================================================
' Form code examples for the Get My Groups feature.
' These procedures belong in your Access form's code-behind.
'
' They cannot be imported directly as a module — copy each
' procedure into your form module manually.
'
' FORM CONTROLS REQUIRED:
'   txtGroupList          Text box — displays returned group names
'   lblGroupCount         Label — displays group count
'   cmdGetGroups          Command button — triggers retrieval
'
' DEPENDENCIES:
'   modGetMyGroups.bas            (GetMyGroups)
'   modVBAuthGlobalConstants.bas
'   JSONConverter.bas             (Tim Hall VBA-JSON)
'
' PREREQUISITE:
'   lclVBAuthAdmin must contain a correctly configured record
'   for this feature. See README.md for required values.
' ============================================================

Option Compare Database
Option Explicit

' ============================================================
' cmdGetGroups_Click
' Calls GetMyGroups to retrieve the authenticated user's AAD
' group memberships via Graph API. Displays the sorted group
' list and count in the form output controls.
' ============================================================
Private Sub cmdGetGroups_Click()

Dim strGroupList    As String
Dim lngGroupCount   As Long

    Me.txtGroupList = "Retrieving groups..."
    Me.lblGroupCount.Caption = "Group count: -"
    Me.Repaint

    If GetMyGroups(strGroupList, lngGroupCount) Then
        Me.txtGroupList = strGroupList
        Me.lblGroupCount.Caption = "Group count: " & lngGroupCount
    Else
        Me.txtGroupList = ""
        Me.lblGroupCount.Caption = "Group count: -"
        MsgBox "Failed to retrieve groups." & vbCrLf & vbCrLf & strMessage, _
               vbCritical, "Get My Groups"
    End If

End Sub
Code language: PHP (php)
Updated on April 4, 2026