VERSION 5.00
Object = "{0D452EE1-E08F-101A-852E-02608C4D0BB4}#2.0#0"; "FM20.DLL"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.UserControl MKTRightsAdmin 
   ClientHeight    =   10410
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   11970
   ScaleHeight     =   10410
   ScaleWidth      =   11970
   Begin VB.Frame fra_frames 
      Caption         =   "Error"
      ForeColor       =   &H00008000&
      Height          =   1905
      Index           =   9
      Left            =   5850
      TabIndex        =   53
      Top             =   7620
      Visible         =   0   'False
      Width           =   2865
      Begin Project1.ArmGrid grd_Error 
         Height          =   2445
         Index           =   9
         Left            =   270
         TabIndex        =   55
         Top             =   1200
         Width           =   10275
         _ExtentX        =   18124
         _ExtentY        =   4313
      End
      Begin VB.Label lbl_labels 
         Caption         =   "#ERROR - RECORDS NOT TRAITED"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   12
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000000FF&
         Height          =   345
         Index           =   9
         Left            =   210
         TabIndex        =   54
         Tag             =   "labelError"
         Top             =   360
         Width           =   10485
      End
   End
   Begin VB.Frame fra_frames 
      Caption         =   "Update"
      ForeColor       =   &H00008000&
      Height          =   1965
      Index           =   4
      Left            =   240
      TabIndex        =   21
      Tag             =   "A"
      Top             =   3390
      Visible         =   0   'False
      Width           =   2295
      Begin VB.Frame Fra_SubFrames 
         Caption         =   "Link Selector"
         Height          =   3525
         Index           =   4
         Left            =   270
         TabIndex        =   22
         Top             =   3450
         Width           =   8805
         Begin VB.CommandButton btn_AddSel 
            Caption         =   "->"
            BeginProperty Font 
               Name            =   "Courier New"
               Size            =   21.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   540
            Index           =   4
            Left            =   3600
            TabIndex        =   24
            Top             =   930
            Width           =   855
         End
         Begin VB.CommandButton btn_DelSel 
            Caption         =   "<-"
            BeginProperty Font 
               Name            =   "Courier New"
               Size            =   21.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   525
            Index           =   4
            Left            =   3570
            TabIndex        =   23
            Top             =   1890
            Width           =   855
         End
         Begin Project1.ArmGrid grd_LinkList 
            Height          =   1155
            Index           =   4
            Left            =   5640
            TabIndex        =   25
            Top             =   630
            Width           =   2415
            _ExtentX        =   4260
            _ExtentY        =   2037
         End
         Begin Project1.ArmGrid grd_AvailList 
            Height          =   1305
            Index           =   4
            Left            =   210
            TabIndex        =   26
            Top             =   510
            Width           =   2385
            _ExtentX        =   4207
            _ExtentY        =   2302
         End
      End
      Begin Project1.ArmGrid grd_Temp 
         Height          =   1155
         Index           =   4
         Left            =   360
         TabIndex        =   27
         Top             =   1710
         Width           =   6015
         _ExtentX        =   10610
         _ExtentY        =   2037
      End
      Begin MSForms.CheckBox chk_StratCountry 
         Height          =   285
         Index           =   4
         Left            =   1380
         TabIndex        =   29
         Tag             =   "Strat_Country®©"
         Top             =   2940
         Width           =   285
         BackColor       =   -2147483633
         ForeColor       =   -2147483630
         DisplayStyle    =   4
         Size            =   "503;503"
         Value           =   "0"
         FontHeight      =   165
         FontCharSet     =   0
         FontPitchAndFamily=   2
      End
      Begin VB.Label lbl_labels 
         Caption         =   "#Strategic User"
         Height          =   255
         Index           =   4
         Left            =   180
         TabIndex        =   28
         Tag             =   "labelStrat"
         Top             =   2970
         Width           =   1185
      End
   End
   Begin VB.Frame fra_frames 
      Caption         =   "Apply Same"
      ForeColor       =   &H00008000&
      Height          =   1905
      Index           =   8
      Left            =   2940
      TabIndex        =   48
      Top             =   7560
      Visible         =   0   'False
      Width           =   2625
      Begin VB.Frame Fra_SubFrames 
         Caption         =   "Link Selector"
         Height          =   3525
         Index           =   8
         Left            =   270
         TabIndex        =   49
         Top             =   3450
         Width           =   8805
         Begin Project1.ArmGrid grd_LinkList 
            Height          =   1155
            Index           =   8
            Left            =   270
            TabIndex        =   50
            Top             =   360
            Width           =   2415
            _ExtentX        =   4260
            _ExtentY        =   2037
         End
      End
      Begin Project1.ArmGrid grd_Temp 
         Height          =   1155
         Index           =   8
         Left            =   360
         TabIndex        =   51
         Top             =   1710
         Width           =   6015
         _ExtentX        =   10610
         _ExtentY        =   2037
      End
      Begin Project1.ArmGrid grd_Selection 
         Height          =   1125
         Index           =   8
         Left            =   300
         TabIndex        =   52
         Top             =   450
         Width           =   5865
         _ExtentX        =   10345
         _ExtentY        =   1984
      End
   End
   Begin VB.Frame fra_frames 
      Caption         =   "Update"
      ForeColor       =   &H00008000&
      Height          =   2115
      Index           =   7
      Left            =   210
      TabIndex        =   41
      Tag             =   "A"
      Top             =   7500
      Visible         =   0   'False
      Width           =   2565
      Begin VB.Frame Fra_SubFrames 
         Caption         =   "Link Selector"
         Height          =   3525
         Index           =   7
         Left            =   270
         TabIndex        =   42
         Top             =   3450
         Width           =   8805
         Begin VB.CommandButton btn_DelSel 
            Caption         =   "<-"
            BeginProperty Font 
               Name            =   "Courier New"
               Size            =   21.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   525
            Index           =   7
            Left            =   3570
            TabIndex        =   44
            Top             =   1890
            Width           =   855
         End
         Begin VB.CommandButton btn_AddSel 
            Caption         =   "->"
            BeginProperty Font 
               Name            =   "Courier New"
               Size            =   21.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   540
            Index           =   7
            Left            =   3600
            TabIndex        =   43
            Top             =   930
            Width           =   855
         End
         Begin Project1.ArmGrid grd_LinkList 
            Height          =   1155
            Index           =   7
            Left            =   5640
            TabIndex        =   45
            Top             =   630
            Width           =   2415
            _ExtentX        =   4260
            _ExtentY        =   2037
         End
         Begin Project1.ArmGrid grd_AvailList 
            Height          =   1305
            Index           =   7
            Left            =   210
            TabIndex        =   46
            Top             =   510
            Width           =   2385
            _ExtentX        =   4207
            _ExtentY        =   2302
         End
      End
      Begin Project1.ArmGrid grd_Temp 
         Height          =   1155
         Index           =   7
         Left            =   240
         TabIndex        =   47
         Top             =   480
         Width           =   6015
         _ExtentX        =   10610
         _ExtentY        =   2037
      End
   End
   Begin VB.Frame fra_frames 
      Caption         =   "Apply Same"
      ForeColor       =   &H00008000&
      Height          =   1965
      Index           =   5
      Left            =   2820
      TabIndex        =   36
      Top             =   3390
      Visible         =   0   'False
      Width           =   2355
      Begin VB.Frame Fra_SubFrames 
         Caption         =   "Link Selector"
         Height          =   3525
         Index           =   5
         Left            =   270
         TabIndex        =   37
         Top             =   3450
         Width           =   8805
         Begin Project1.ArmGrid grd_LinkList 
            Height          =   1155
            Index           =   5
            Left            =   270
            TabIndex        =   38
            Top             =   360
            Width           =   2415
            _ExtentX        =   4260
            _ExtentY        =   2037
         End
      End
      Begin Project1.ArmGrid grd_Temp 
         Height          =   1155
         Index           =   5
         Left            =   360
         TabIndex        =   39
         Top             =   1710
         Width           =   6015
         _ExtentX        =   10610
         _ExtentY        =   2037
      End
      Begin Project1.ArmGrid grd_Selection 
         Height          =   1125
         Index           =   5
         Left            =   300
         TabIndex        =   40
         Top             =   450
         Width           =   5865
         _ExtentX        =   10345
         _ExtentY        =   1984
      End
   End
   Begin VB.Frame fra_frames 
      Caption         =   "Copy"
      ForeColor       =   &H00008000&
      Height          =   1905
      Index           =   6
      Left            =   5430
      TabIndex        =   30
      Top             =   3390
      Visible         =   0   'False
      Width           =   2805
      Begin VB.Frame Fra_SubFrames 
         Caption         =   "Link Selector"
         Height          =   3525
         Index           =   6
         Left            =   270
         TabIndex        =   31
         Top             =   3450
         Width           =   8805
         Begin Project1.ArmGrid grd_LinkList 
            Height          =   1155
            Index           =   6
            Left            =   5640
            TabIndex        =   32
            Top             =   630
            Width           =   2415
            _ExtentX        =   4260
            _ExtentY        =   2037
         End
         Begin Project1.ArmGrid grd_AvailList 
            Height          =   1305
            Index           =   6
            Left            =   210
            TabIndex        =   33
            Top             =   510
            Width           =   2385
            _ExtentX        =   4207
            _ExtentY        =   2302
         End
      End
      Begin Project1.ArmGrid grd_Temp 
         Height          =   1155
         Index           =   6
         Left            =   360
         TabIndex        =   34
         Top             =   1710
         Width           =   6015
         _ExtentX        =   10610
         _ExtentY        =   2037
      End
      Begin Project1.ArmGrid grd_Selection 
         Height          =   1125
         Index           =   6
         Left            =   300
         TabIndex        =   35
         Top             =   450
         Width           =   5865
         _ExtentX        =   10345
         _ExtentY        =   1984
      End
   End
   Begin VB.Frame fra_frames 
      Caption         =   "Delete"
      ForeColor       =   &H00008000&
      Height          =   1845
      Index           =   3
      Left            =   7980
      TabIndex        =   18
      Tag             =   "A"
      Top             =   1170
      Visible         =   0   'False
      Width           =   2205
      Begin Project1.ArmGrid grd_Temp 
         Height          =   1155
         Index           =   3
         Left            =   360
         TabIndex        =   19
         Top             =   1710
         Width           =   6015
         _ExtentX        =   10610
         _ExtentY        =   2037
      End
      Begin Project1.ArmGrid grd_Selection 
         Height          =   1125
         Index           =   3
         Left            =   300
         TabIndex        =   20
         Top             =   450
         Width           =   5865
         _ExtentX        =   10345
         _ExtentY        =   1984
      End
   End
   Begin VB.Frame fra_frames 
      Caption         =   "Add"
      ForeColor       =   &H00008000&
      Height          =   1815
      Index           =   2
      Left            =   5640
      TabIndex        =   8
      Tag             =   "A"
      Top             =   1170
      Visible         =   0   'False
      Width           =   2175
      Begin VB.Frame Fra_SubFrames 
         Caption         =   "Link Selector"
         Height          =   3525
         Index           =   2
         Left            =   270
         TabIndex        =   13
         Top             =   3450
         Width           =   8805
         Begin VB.CommandButton btn_DelSel 
            Caption         =   "<-"
            BeginProperty Font 
               Name            =   "Courier New"
               Size            =   21.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   525
            Index           =   2
            Left            =   3570
            TabIndex        =   17
            Top             =   1890
            Width           =   855
         End
         Begin VB.CommandButton btn_AddSel 
            Caption         =   "->"
            BeginProperty Font 
               Name            =   "Courier New"
               Size            =   21.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   540
            Index           =   2
            Left            =   3570
            TabIndex        =   16
            Top             =   930
            Width           =   855
         End
         Begin Project1.ArmGrid grd_LinkList 
            Height          =   1155
            Index           =   2
            Left            =   5640
            TabIndex        =   15
            Top             =   630
            Width           =   2415
            _ExtentX        =   4260
            _ExtentY        =   2037
         End
         Begin Project1.ArmGrid grd_AvailList 
            Height          =   1305
            Index           =   2
            Left            =   210
            TabIndex        =   14
            Top             =   510
            Width           =   2385
            _ExtentX        =   4207
            _ExtentY        =   2302
         End
      End
      Begin Project1.ArmGrid grd_Temp 
         Height          =   1155
         Index           =   2
         Left            =   360
         TabIndex        =   10
         Top             =   1710
         Width           =   6015
         _ExtentX        =   10610
         _ExtentY        =   2037
      End
      Begin Project1.ArmGrid grd_Selection 
         Height          =   1125
         Index           =   2
         Left            =   300
         TabIndex        =   9
         Top             =   450
         Width           =   5865
         _ExtentX        =   10345
         _ExtentY        =   1984
      End
      Begin VB.Label lbl_labels 
         Caption         =   "#Strategic User"
         Height          =   255
         Index           =   2
         Left            =   180
         TabIndex        =   12
         Tag             =   "labelStrat"
         Top             =   2970
         Width           =   1185
      End
      Begin MSForms.CheckBox chk_StratCountry 
         Height          =   285
         Index           =   2
         Left            =   1380
         TabIndex        =   11
         Tag             =   "Strat_Country®©"
         Top             =   2940
         Width           =   285
         BackColor       =   -2147483633
         ForeColor       =   -2147483630
         DisplayStyle    =   4
         Size            =   "503;503"
         Value           =   "0"
         FontHeight      =   165
         FontCharSet     =   0
         FontPitchAndFamily=   2
      End
   End
   Begin VB.Frame fra_frames 
      Caption         =   "Main"
      ForeColor       =   &H00008000&
      Height          =   1815
      Index           =   1
      Left            =   2970
      TabIndex        =   3
      Top             =   1170
      Visible         =   0   'False
      Width           =   2535
      Begin Project1.ArmGrid grd_List 
         Height          =   1395
         Index           =   1
         Left            =   150
         TabIndex        =   6
         Tag             =   "User_Main_Auth"
         Top             =   690
         Width           =   6525
         _ExtentX        =   11509
         _ExtentY        =   2461
      End
      Begin Project1.ArmGrid grd_Linked 
         Height          =   1395
         Index           =   1
         Left            =   150
         TabIndex        =   7
         Top             =   2460
         Width           =   6525
         _ExtentX        =   11509
         _ExtentY        =   2461
      End
   End
   Begin MSComctlLib.TabStrip tbs_tab 
      Height          =   315
      Left            =   0
      TabIndex        =   2
      Top             =   720
      Visible         =   0   'False
      Width           =   5385
      _ExtentX        =   9499
      _ExtentY        =   556
      MultiRow        =   -1  'True
      _Version        =   393216
      BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
         NumTabs         =   2
         BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            Caption         =   "Users Interface"
            Object.Tag             =   "0"
            ImageVarType    =   2
         EndProperty
         BeginProperty Tab2 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
            Caption         =   "Masters Interface"
            Object.Tag             =   "1"
            ImageVarType    =   2
         EndProperty
      EndProperty
   End
   Begin Project1.ToolbarControl tlb_Main 
      Height          =   690
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Visible         =   0   'False
      Width           =   5175
      _ExtentX        =   9128
      _ExtentY        =   1217
   End
   Begin VB.Frame fra_frames 
      Caption         =   "Main"
      ForeColor       =   &H00008000&
      Height          =   1815
      Index           =   0
      Left            =   210
      TabIndex        =   1
      Tag             =   "Main"
      Top             =   1170
      Visible         =   0   'False
      Width           =   2595
      Begin Project1.ArmGrid grd_List 
         Height          =   1125
         Index           =   0
         Left            =   210
         TabIndex        =   4
         Tag             =   "User_Main_Auth"
         Top             =   360
         Width           =   3975
         _ExtentX        =   7011
         _ExtentY        =   1984
      End
      Begin Project1.ArmGrid grd_Linked 
         Height          =   915
         Index           =   0
         Left            =   210
         TabIndex        =   5
         Top             =   1530
         Width           =   3945
         _ExtentX        =   6959
         _ExtentY        =   1614
      End
   End
End
Attribute VB_Name = "MKTRightsAdmin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private Const SEP1 As String = "®"
Private Const SEP2 As String = "©"
Private Const SEP As String = "®©"

Const C_ERRORRAISE As Long = 10000

Private Const SCREEN_NAME As String = "MKT_RightsAdmin"    ' for loading screen constants
Private Const SYSTEM_CODE As Long = 13

Public Event quit()


Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwnd As Long) As Long


Private Enum ArmErr
    DBCnxFailed = C_ERRORRAISE + 1             ' Unable to connect to the database
    CPTAlreadyInitialized = C_ERRORRAISE + 2   ' We try to initialize a component that is already initialized
    CPTNotInitialized = C_ERRORRAISE + 3       ' We try to use or free that is not initialized yet
    InvalidArgument = C_ERRORRAISE + 4
    PropertyNotSet = C_ERRORRAISE + 5
    SQLFailure = C_ERRORRAISE + 6               ' A SQL runtime error has occured : syntax wrong....
    SQLBadRowAffectedCount = C_ERRORRAISE + 7   ' A SQL request has not affected the expected rowcount (ex: one Update do nothing)
    SQLBadRowExpectedCount = C_ERRORRAISE + 8   ' A SQL request does not return the expected rowcount : select an item return nothing...
    DrivingError = C_ERRORRAISE + 9
    CompFncFailed = C_ERRORRAISE + 10           ' when component function fail
    GridLoadFailed = C_ERRORRAISE + 11          ' load function failed ... bad sql
End Enum

Private Enum ArmCusErr
    DuplicityDetected = C_ERRORRAISE + 2301                ' detected row with same unique id
End Enum

Private mb_Initialized              As Boolean

Dim ml_U_code As Long               ' if this is user loging app, needed to log errors into A_Log
Dim ms_Language_Code As String


#If LIVE = 1 Then
    Dim mo_Db As Object
#Else
    Dim mo_Db As ARMSYSCOMLib.ArmDb
#End If

Private Type TConfigRecord
    IndexFrame                      As Long
    NameFrame                       As String
    IsInit                          As Boolean
    RequestToApply                  As String
    ListFieldsToDisable             As Variant
    ListFieldsMandatory             As Variant
    ListFieldsDefaultValue          As Variant
    DeleteMsg(0, 1)                 As String
    UpdateMsg(0, 1)                 As String
    CheckMsg(0, 1)                  As String
    CheckDelMsg(0, 1)               As String
End Type

Private Type TConfigGrid
    Grid                            As ArmGrid
    Title                           As String
    AllowExcelExp                   As Boolean
    ExportTitle                     As Boolean
    MultiSel                        As Boolean
    FetchAll                        As Boolean
    UnBound                         As Boolean
    Load                            As Boolean
    Tag                             As String
    Visible                         As Boolean
    Enabled                         As Boolean
    Request                         As String
    Columns()                       As String
    Labels                          As String
End Type

Private Type TConfigDetail
    FaceToolbar                     As String
    ConfigGrid()                    As TConfigGrid ' if request = "" -> grid not used
End Type


Private Type TClassInfo
    ConfigDetail                    As TConfigDetail
    ConfigRecord                    As TConfigRecord
End Type

Private mt_ClassInfoLst()           As TClassInfo

Dim ms_ListSelection                As String
Dim ms_ListToLink                   As String
Dim ms_ListToUnLink                 As String

Dim ms_Errors                       As String


Dim ml_AcitveClassIndex             As Long

Public Property Let U_Code(ByVal al_U_code As Long)
    ml_U_code = al_U_code
End Property

Public Property Let Language_Code(as_Language_code As String)
    ms_Language_Code = as_Language_code
End Property

Public Property Set Db(ByRef aDb As ArmDb)
    Set mo_Db = aDb
End Property
Public Property Let Visible(ByVal aVisible As Boolean)
    UserControl.Extender.Visible = aVisible
End Property
Public Property Get Visible() As Boolean
    Visible = UserControl.Extender.Visible
End Property

Public Sub Move(ByVal aLeft As Single, ByVal aTop As Single, ByVal aWidth As Single, ByVal aHeight As Single)
    Call UserControl.Extender.Move(aLeft, aTop, aWidth, aHeight)
End Sub
Private Sub Load_ClassInfo()
On Error GoTo errHandler
    Dim ClassInfoNb As Long
    Dim grdNb As Long
    Dim ColNb As Long
    Dim ClassInfoNum As Long
    Dim grdNum As Long
    Dim ColNum As Long
    
    ClassInfoNb = 10
    
    ReDim mt_ClassInfoLst(ClassInfoNb)
    
    ClassInfoNum = 0
    With mt_ClassInfoLst(ClassInfoNum)
        With .ConfigRecord
            .IndexFrame = 0
            .NameFrame = "Main_User"
            .IsInit = False
            
            
        End With
        
        With .ConfigDetail
            grdNb = 1
            ReDim .ConfigGrid(grdNb)
            
            grdNum = 0
            Set .ConfigGrid(grdNum).Grid = grd_List(0)
            
            ColNb = 6
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_Code", 0, 1, "U_Code", "#U_Code"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_First_Name", 3000, 0, "P_First_Name", "#First_Name"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_Name", 3000, 0, "P_Name", "#Surname"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_login_name", 2000, 0, "U_login_name", "#Login ID"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_desc", 2000, 0, "CT_desc", "#Country"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("D_Description", 2000, 0, "D_Description", "#Department"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("Strat_Country", 1300, 0, "Strat_Country", "#Strategic"), SEP)
            
            
            .ConfigGrid(grdNum).Request = "exec MKT_UR_Authorised_Users_lst NULL, NULL"
            .ConfigGrid(grdNum).Title = "#Authorised Users"
            .ConfigGrid(grdNum).Tag = SEP & "grd_List"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = False
            .ConfigGrid(grdNum).FetchAll = False
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = False
            .ConfigGrid(grdNum).Load = True
            
            grdNum = grdNum + 1
            Set .ConfigGrid(grdNum).Grid = grd_Linked(0)
            
            ColNb = 1
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("Comp_Desc", 4000, 0, "Comp_Desc", "#Competitor"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_desc", 4000, 0, "CT_desc", "#Country"), SEP)
            
            .ConfigGrid(grdNum).Request = "exec MKT_UR_Authorised_Masters_lst $KEY$"
            .ConfigGrid(grdNum).Title = "#Authorised Masters Records for Selected User"
            .ConfigGrid(grdNum).Tag = SEP & "grd_Linked"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = False
            .ConfigGrid(grdNum).FetchAll = True
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = False
            .ConfigGrid(grdNum).Load = False
            
            .FaceToolbar = 0
        
        End With
    End With
    
    ClassInfoNum = ClassInfoNum + 1
    With mt_ClassInfoLst(ClassInfoNum)
        With .ConfigRecord
            .IndexFrame = 1
            .NameFrame = "Main_Master"
            .IsInit = False
        End With
        
        With .ConfigDetail
            grdNb = 1
            ReDim .ConfigGrid(grdNb)
            grdNum = 0
            Set .ConfigGrid(grdNum).Grid = grd_List(1)
            
            ColNb = 2
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("MKT_Key", 0, 1, "MKT_Key", "#MKT_Key"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("Comp_Desc", 4000, 0, "Comp_Desc", "#Comp_Desc"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_desc", 4000, 0, "CT_desc", "#CT_desc"), SEP)
            
            .ConfigGrid(grdNum).Request = "exec MKT_UR_Masters_lst"
            .ConfigGrid(grdNum).Title = "#All Masters"
            .ConfigGrid(grdNum).Tag = SEP & "grd_List"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = False
            .ConfigGrid(grdNum).FetchAll = False
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = False
            .ConfigGrid(grdNum).Load = True
            
            grdNum = grdNum + 1
            Set .ConfigGrid(grdNum).Grid = grd_Linked(1)
            
            ColNb = 4
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_First_Name", 3000, 0, "P_First_Name", "#First_Name"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_Name", 3000, 0, "P_Name", "#Surname"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_login_name", 2000, 0, "U_login_name", "#Login ID"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_desc", 2000, 0, "CT_desc", "#Country"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("D_Description", 2000, 0, "D_Description", "#Department"), SEP)
            
            .ConfigGrid(grdNum).Request = "exec MKT_UR_Authorised_Users_lst $KEY$,NULL"
            .ConfigGrid(grdNum).Title = "#Authorised Users for Selected Master"
            .ConfigGrid(grdNum).Tag = SEP & "grd_Linked"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = False
            .ConfigGrid(grdNum).FetchAll = True
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = False
            .ConfigGrid(grdNum).Load = False
            
            .FaceToolbar = 1
        
        End With
    End With

'ADD
    ClassInfoNum = ClassInfoNum + 1
    With mt_ClassInfoLst(ClassInfoNum)
        With .ConfigRecord
            .IndexFrame = 2
            .NameFrame = "ADD_User"
            .IsInit = False
            
            .RequestToApply = "exec MKT_UR_Auhtorised_Users_Ins $U_CODE$, '$STRAT_COUNTRY$', $SYSTEM_CODE$, $Z_USER$" & SEP & _
                          "exec MKT_UR_Security_Users_Ins $MKT_KEY$, $U_CODE$, $SYSTEM_CODE$"
             
        End With
        
        With .ConfigDetail
            grdNb = 3
            ReDim .ConfigGrid(grdNb)

'------------------------------------------------
            grdNum = 0
            Set .ConfigGrid(grdNum).Grid = grd_Selection(2)
            
            ColNb = 5
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_code", 0, 1, "U_code", "#U_code"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_First_Name", 3000, 0, "P_First_Name", "#First_Name"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_Name", 3000, 0, "P_Name", "#Surname"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_login_name", 2000, 0, "U_login_name", "#Login ID"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_desc", 2000, 0, "CT_desc", "#Country"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("D_Description", 2000, 0, "D_Description", "#Department"), SEP)
            
            .ConfigGrid(grdNum).Request = "exec MKT_UR_User_Available_lst"
            .ConfigGrid(grdNum).Title = "#Available Users"
            .ConfigGrid(grdNum).Tag = SEP & "grd_Selection"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = True
            .ConfigGrid(grdNum).FetchAll = False
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = False
            .ConfigGrid(grdNum).Load = True

'------------------------------------------------
            grdNum = grdNum + 1
            Set .ConfigGrid(grdNum).Grid = grd_Temp(2)
            
            ColNb = 5
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_code", 0, 1, "U_code", "#U_code"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_First_Name", 3000, 0, "P_First_Name", "#First_Name"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_Name", 3000, 0, "P_Name", "#Surname"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_login_name", 2000, 0, "U_login_name", "#Login ID"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_desc", 2000, 0, "CT_desc", "#Country"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("D_Description", 2000, 0, "D_Description", "#Department"), SEP)
            
            .ConfigGrid(grdNum).Request = ""
            .ConfigGrid(grdNum).Title = "#Selected Users"
            .ConfigGrid(grdNum).Tag = "Colored" & SEP & "grd_Temp"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = True
            .ConfigGrid(grdNum).FetchAll = False
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = True
            .ConfigGrid(grdNum).Load = False
            
'------------------------------------------------
            grdNum = grdNum + 1
            Set .ConfigGrid(grdNum).Grid = grd_AvailList(2)
            
            ColNb = 2
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("MKT_Key", 0, 1, "MKT_Key", "#MKT_Key"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("Comp_Desc", 4000, 0, "Comp_Desc", "#Competitor"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_Desc", 4000, 0, "CT_Desc", "#Country"), SEP)
            
            .ConfigGrid(grdNum).Request = "exec MKT_UR_Masters_lst"
            .ConfigGrid(grdNum).Title = "#List of Masters"
            .ConfigGrid(grdNum).Tag = SEP & "grd_AvailList"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = True
            .ConfigGrid(grdNum).FetchAll = False
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = False
            .ConfigGrid(grdNum).Load = True
            
'----------------------------------------------------------
            grdNum = grdNum + 1
            Set .ConfigGrid(grdNum).Grid = grd_LinkList(2)
            
            ColNb = 2
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("MKT_Key", 0, 1, "MKT_Key", "#MKT_Key"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("Comp_Desc", 4000, 0, "Comp_Desc", "#Competitor"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_Desc", 4000, 0, "CT_Desc", "#Country"), SEP)
            
            .ConfigGrid(grdNum).Request = ""
            .ConfigGrid(grdNum).Title = "#Selected Masters To Link"
            .ConfigGrid(grdNum).Tag = "Colored" & SEP & "grd_LinkList"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = True
            .ConfigGrid(grdNum).FetchAll = False
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = True
            .ConfigGrid(grdNum).Load = False
            
            .FaceToolbar = 2
        
        End With
    End With
    
'DEL
    ClassInfoNum = ClassInfoNum + 1
    With mt_ClassInfoLst(ClassInfoNum)
        With .ConfigRecord
            .IndexFrame = 3
            .NameFrame = "DEL_User"
            .IsInit = False
            
            .RequestToApply = "exec MKT_UR_Security_Users_Del NULL,$U_CODE$" & SEP & _
                "exec MKT_UR_Auhtorised_Users_Del $U_CODE$"

        End With
        
        With .ConfigDetail
            grdNb = 1
            ReDim .ConfigGrid(grdNb)

'------------------------------------------------
            grdNum = 0
            Set .ConfigGrid(grdNum).Grid = grd_Selection(3)
            
            ColNb = 6
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_code", 0, 1, "U_code", "#U_code"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_First_Name", 3000, 0, "P_First_Name", "#First_Name"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_Name", 3000, 0, "P_Name", "#Surname"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_login_name", 2000, 0, "U_login_name", "#Login ID"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_desc", 2000, 0, "CT_desc", "#Country"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("D_Description", 2000, 0, "D_Description", "#Department"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("Strat_Country", 1300, 0, "Strat_Country", "#Strategic"), SEP)
            
            .ConfigGrid(grdNum).Request = "exec MKT_UR_Authorised_Users_lst NULL,NULL"
            .ConfigGrid(grdNum).Title = "#Authorised Users"
            .ConfigGrid(grdNum).Tag = SEP & "grd_Selection"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = True
            .ConfigGrid(grdNum).FetchAll = False
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = False
            .ConfigGrid(grdNum).Load = True

'------------------------------------------------
            grdNum = grdNum + 1
            Set .ConfigGrid(grdNum).Grid = grd_Temp(3)
            
            ColNb = 6
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_code", 0, 1, "U_code", "#U_code"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_First_Name", 3000, 0, "P_First_Name", "#First_Name"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_Name", 3000, 0, "P_Name", "#Surname"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_login_name", 2000, 0, "U_login_name", "#Login ID"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_desc", 2000, 0, "CT_desc", "#Country"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("D_Description", 2000, 0, "D_Description", "#Department"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("Strat_Country", 1300, 0, "Strat_Country", "#Strategic"), SEP)
            
            .ConfigGrid(grdNum).Request = ""
            .ConfigGrid(grdNum).Title = "#Selected Users"
            .ConfigGrid(grdNum).Tag = "Colored" & SEP & "grd_Temp"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = True
            .ConfigGrid(grdNum).FetchAll = False
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = True
            .ConfigGrid(grdNum).Load = False
            
            .FaceToolbar = 3
        
        End With
    End With
    
'UPD

    ClassInfoNum = ClassInfoNum + 1
    With mt_ClassInfoLst(ClassInfoNum)
        With .ConfigRecord
            .IndexFrame = 4
            .NameFrame = "UPD_User"
            .IsInit = False
            
            .RequestToApply = "exec MKT_UR_Auhtorised_Users_Upd $U_CODE$, '$STRAT_COUNTRY$', $SYSTEM_CODE$, $Z_USER$, $ICONCURRENCY$" & SEP & _
                              "exec MKT_UR_Security_Users_Ins $MKT_KEY$, $U_CODE$, $SYSTEM_CODE$" & SEP & _
                              "exec MKT_UR_Security_Users_Del $MKT_KEY$, $U_CODE$"
        End With
        
        With .ConfigDetail
            grdNb = 2
            ReDim .ConfigGrid(grdNb)

'------------------------------------------------
            grdNum = 0
            Set .ConfigGrid(grdNum).Grid = grd_Temp(4)
            
            ColNb = 6
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_code", 0, 1, "U_code", "#U_code"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_First_Name", 3000, 0, "P_First_Name", "#First_Name"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_Name", 3000, 0, "P_Name", "#Surname"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_login_name", 2000, 0, "U_login_name", "#Login ID"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_desc", 2000, 0, "CT_desc", "#Country"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("D_Description", 2000, 0, "D_Description", "#Department"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("iConcurrency", 0, 0, "iConcurrency", "#iConcurrency"), SEP)
            
            .ConfigGrid(grdNum).Request = "exec MKT_UR_Authorised_Users_lst NULL, $KEY$"
            .ConfigGrid(grdNum).Title = "#Authorised User Seleted"
            .ConfigGrid(grdNum).Tag = "Colored" & SEP & "grd_Temp"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = True
            .ConfigGrid(grdNum).FetchAll = True
             
            .ConfigGrid(grdNum).Enabled = False
            
            .ConfigGrid(grdNum).UnBound = False
            .ConfigGrid(grdNum).Load = False
            
'------------------------------------------------
            grdNum = grdNum + 1
            Set .ConfigGrid(grdNum).Grid = grd_AvailList(4)
            
            ColNb = 2
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("MKT_Key", 0, 1, "MKT_Key", "#MKT_Key"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("Comp_Desc", 4000, 0, "Comp_Desc", "#Competitor"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_Desc", 4000, 0, "CT_Desc", "#Country"), SEP)
            
            .ConfigGrid(grdNum).Request = "exec MKT_UR_Masters_lst $KEY$"
            .ConfigGrid(grdNum).Title = "#List of Masters"
            .ConfigGrid(grdNum).Tag = SEP & "grd_AvailList"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = True
            .ConfigGrid(grdNum).FetchAll = False
             
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = False
            .ConfigGrid(grdNum).Load = False
            
'-----------------------------------------------------------------
            grdNum = grdNum + 1
            Set .ConfigGrid(grdNum).Grid = grd_LinkList(4)
            
            ColNb = 2
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("MKT_Key", 0, 1, "MKT_Key", "#MKT_Key"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("Comp_Desc", 4000, 0, "Comp_Desc", "#Competitor"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_Desc", 4000, 0, "CT_Desc", "#Country"), SEP)
            
            .ConfigGrid(grdNum).Request = "exec MKT_UR_Authorised_Masters_lst $KEY$"
            .ConfigGrid(grdNum).Title = "#List of Masters To Link"
            .ConfigGrid(grdNum).Tag = "Colored" & SEP & "grd_LinkList"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = True
            .ConfigGrid(grdNum).FetchAll = True
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = False
            .ConfigGrid(grdNum).Load = False
            
            .FaceToolbar = 4
        
        End With
    End With
    
'SAME

    ClassInfoNum = ClassInfoNum + 1
    With mt_ClassInfoLst(ClassInfoNum)
        With .ConfigRecord
            .IndexFrame = 5
            .NameFrame = "SAME_User"
            .IsInit = False
            
            .RequestToApply = "exec MKT_UR_Auhtorised_Users_Upd $U_CODE$, '$STRAT_COUNTRY$', $SYSTEM_CODE$, $Z_USER$, $ICONCURRENCY$" & SEP & _
                              "exec MKT_UR_Security_Users_Del NULL,$U_CODE$" & SEP & _
                              "exec MKT_UR_Security_Users_Ins $MKT_KEY$, $U_CODE$, $SYSTEM_CODE$"
        End With


'------------------------------------------------
        With .ConfigDetail
            grdNb = 2
            ReDim .ConfigGrid(grdNb)

'------------------------------------------------
            grdNum = 0
            Set .ConfigGrid(grdNum).Grid = grd_Selection(5)
            
            ColNb = 6
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_code", 0, 1, "U_code", "#U_code"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_First_Name", 3000, 0, "P_First_Name", "#First_Name"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_Name", 3000, 0, "P_Name", "#Surname"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_login_name", 2000, 0, "U_login_name", "#Login ID"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_desc", 2000, 0, "CT_desc", "#Country"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("D_Description", 2000, 0, "D_Description", "#Department"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("iConcurrency", 0, 0, "iConcurrency", "#iConcurrency"), SEP)
            
            .ConfigGrid(grdNum).Request = "exec MKT_UR_Authorised_Users_lst NULL, NULL,''"
            .ConfigGrid(grdNum).Title = "#Authorised Users Not Strategic"
            .ConfigGrid(grdNum).Tag = SEP & "grd_Selection"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = True
            .ConfigGrid(grdNum).FetchAll = False
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = False
            .ConfigGrid(grdNum).Load = True

'------------------------------------------------
            grdNum = grdNum + 1
            Set .ConfigGrid(grdNum).Grid = grd_Temp(5)
            
            ColNb = 6
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_code", 0, 1, "U_code", "#U_code"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_First_Name", 3000, 0, "P_First_Name", "#First_Name"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_Name", 3000, 0, "P_Name", "#Surname"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_login_name", 2000, 0, "U_login_name", "#Login ID"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_desc", 2000, 0, "CT_desc", "#Country"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("D_Description", 2000, 0, "D_Description", "#Department"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("iConcurrency", 0, 0, "iConcurrency", "#iConcurrency"), SEP)
            
            .ConfigGrid(grdNum).Request = ""
            .ConfigGrid(grdNum).Title = "#Selected Users"
            .ConfigGrid(grdNum).Tag = "Colored" & SEP & "grd_Temp"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = True
            .ConfigGrid(grdNum).FetchAll = False
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = True
            .ConfigGrid(grdNum).Load = False
            

            
'----------------------------------------------------------
            grdNum = grdNum + 1
            Set .ConfigGrid(grdNum).Grid = grd_LinkList(5)
            
            ColNb = 2
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("MKT_Key", 0, 1, "MKT_Key", "#MKT_Key"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("Comp_Desc", 4000, 0, "Comp_Desc", "#Competitor"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_Desc", 4000, 0, "CT_Desc", "#Country"), SEP)
            
            .ConfigGrid(grdNum).Request = ""
            .ConfigGrid(grdNum).Title = "#List of Masters To Link"
            .ConfigGrid(grdNum).Tag = "Colored" & SEP & "grd_LinkList"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = True
            .ConfigGrid(grdNum).FetchAll = True
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = True
            .ConfigGrid(grdNum).Load = False
            
            .FaceToolbar = 5
        
        End With
    End With

'CPY
    ClassInfoNum = ClassInfoNum + 1
    With mt_ClassInfoLst(ClassInfoNum)
        With .ConfigRecord
            .IndexFrame = 6
            .NameFrame = "CPY_User"
            .IsInit = False
            
            .RequestToApply = "exec MKT_UR_Auhtorised_Users_Ins $U_CODE$, '', $SYSTEM_CODE$, $Z_USER$" & SEP & _
                          "exec MKT_UR_Security_Users_Ins $MKT_KEY$, $U_CODE$, $SYSTEM_CODE$"
             
        End With
        
        With .ConfigDetail
            grdNb = 3
            ReDim .ConfigGrid(grdNb)

'------------------------------------------------
            grdNum = 0
            Set .ConfigGrid(grdNum).Grid = grd_Selection(6)
            
            ColNb = 5
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_code", 0, 1, "U_code", "#U_code"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_First_Name", 3000, 0, "P_First_Name", "#First_Name"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_Name", 3000, 0, "P_Name", "#Surname"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_login_name", 2000, 0, "U_login_name", "#Login ID"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_desc", 2000, 0, "CT_desc", "#Country"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("D_Description", 2000, 0, "D_Description", "#Department"), SEP)
            
            .ConfigGrid(grdNum).Request = "exec MKT_UR_User_Available_lst"
            .ConfigGrid(grdNum).Title = "#Available Users"
            .ConfigGrid(grdNum).Tag = SEP & "grd_Selection"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = True
            .ConfigGrid(grdNum).FetchAll = False
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = False
            .ConfigGrid(grdNum).Load = True

'------------------------------------------------
            grdNum = grdNum + 1
            Set .ConfigGrid(grdNum).Grid = grd_Temp(6)
            
            ColNb = 5
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_code", 0, 1, "U_code", "#U_code"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_First_Name", 3000, 0, "P_First_Name", "#First_Name"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_Name", 3000, 0, "P_Name", "#Surname"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_login_name", 2000, 0, "U_login_name", "#Login ID"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_desc", 2000, 0, "CT_desc", "#Country"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("D_Description", 2000, 0, "D_Description", "#Department"), SEP)
            
            .ConfigGrid(grdNum).Request = ""
            .ConfigGrid(grdNum).Title = "#Selected Users"
            .ConfigGrid(grdNum).Tag = "Colored" & SEP & "grd_Temp"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = True
            .ConfigGrid(grdNum).FetchAll = False
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = True
            .ConfigGrid(grdNum).Load = False
            
'------------------------------------------------
            grdNum = grdNum + 1
            Set .ConfigGrid(grdNum).Grid = grd_AvailList(6)
            
            ColNb = 5
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_code", 0, 1, "U_code", "#U_code"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_First_Name", 1500, 0, "P_First_Name", "#First_Name"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_Name", 1500, 0, "P_Name", "#Surname"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_login_name", 1500, 0, "U_login_name", "#Login ID"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_desc", 1500, 0, "CT_desc", "#Country"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("D_Description", 1500, 0, "D_Description", "#Department"), SEP)
            
            .ConfigGrid(grdNum).Request = "exec MKT_UR_Authorised_Users_lst NULL, NULL,''"
            .ConfigGrid(grdNum).Title = "#Authorised Users Not Strategic"
            .ConfigGrid(grdNum).Tag = SEP & "grd_AvailList"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = True
            .ConfigGrid(grdNum).FetchAll = False
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = False
            .ConfigGrid(grdNum).Load = True
            
'----------------------------------------------------------
            grdNum = grdNum + 1
            Set .ConfigGrid(grdNum).Grid = grd_LinkList(6)
            
            ColNb = 2
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("MKT_Key", 0, 1, "MKT_Key", "#MKT_Key"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("Comp_Desc", 4000, 0, "Comp_Desc", "#Competitor"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_Desc", 4000, 0, "CT_Desc", "#Country"), SEP)
            
            .ConfigGrid(grdNum).Request = "exec MKT_UR_Authorised_Masters_lst $KEY$"
            .ConfigGrid(grdNum).Title = "#List of Masters To Link"
            .ConfigGrid(grdNum).Tag = "Colored" & SEP & "grd_LinkList"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = False
            .ConfigGrid(grdNum).FetchAll = True
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = False
            .ConfigGrid(grdNum).Load = False
            
            .FaceToolbar = 6
        
        End With
    End With
    
'Master UPD
    ClassInfoNum = ClassInfoNum + 1
    With mt_ClassInfoLst(ClassInfoNum)
        With .ConfigRecord
            .IndexFrame = 7
            .NameFrame = "UPD_Master"
            .IsInit = False
            
            .RequestToApply = "exec MKT_UR_Auhtorised_Users_Upd $U_CODE$, '', $SYSTEM_CODE$, $Z_USER$, $ICONCURRENCY$" & SEP & _
                              "exec MKT_UR_Security_Users_Ins $MKT_KEY$, $U_CODE$, $SYSTEM_CODE$" & SEP & _
                              "exec MKT_UR_Security_Users_Del $MKT_KEY$, $U_CODE$"
        End With
        
        With .ConfigDetail
            grdNb = 2
            ReDim .ConfigGrid(grdNb)

'------------------------------------------------
            grdNum = 0
            Set .ConfigGrid(grdNum).Grid = grd_Temp(7)
            
            ColNb = 2
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("MKT_Key", 0, 1, "MKT_Key", "#MKT_Key"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("Comp_Desc", 4000, 0, "Comp_Desc", "#Competitor"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_Desc", 4000, 0, "CT_Desc", "#Country"), SEP)
            
            .ConfigGrid(grdNum).Request = ""
            .ConfigGrid(grdNum).Title = "#Master Seleted"
            .ConfigGrid(grdNum).Tag = "Colored" & SEP & "grd_Temp"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = True
            .ConfigGrid(grdNum).FetchAll = True
             
            .ConfigGrid(grdNum).Enabled = False
            
            .ConfigGrid(grdNum).UnBound = True
            .ConfigGrid(grdNum).Load = False
            
'------------------------------------------------
            grdNum = grdNum + 1
            Set .ConfigGrid(grdNum).Grid = grd_AvailList(7)
            
            ColNb = 6
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_code", 0, 1, "U_code", "#U_code"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_First_Name", 1500, 0, "P_First_Name", "#First_Name"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_Name", 1500, 0, "P_Name", "#Surname"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_login_name", 1500, 0, "U_login_name", "#Login ID"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_desc", 1500, 0, "CT_desc", "#Country"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("D_Description", 1500, 0, "D_Description", "#Department"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("iConcurrency", 0, 0, "iConcurrency", "#iConcurrency"), SEP)
            
            .ConfigGrid(grdNum).Request = "exec MKT_UR_Authorised_Users_Filtered_lst $KEY$, ''"
            .ConfigGrid(grdNum).Title = "#Authorised Users Not Strategic"
            .ConfigGrid(grdNum).Tag = SEP & "grd_AvailList"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = True
            .ConfigGrid(grdNum).FetchAll = False
             
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = False
            .ConfigGrid(grdNum).Load = False
            
'-----------------------------------------------------------------
            grdNum = grdNum + 1
            Set .ConfigGrid(grdNum).Grid = grd_LinkList(7)
            
            ColNb = 6
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_code", 0, 1, "U_code", "#U_code"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_First_Name", 1500, 0, "P_First_Name", "#First_Name"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_Name", 1500, 0, "P_Name", "#Surname"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_login_name", 1500, 0, "U_login_name", "#Login ID"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_desc", 1500, 0, "CT_desc", "#Country"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("D_Description", 1500, 0, "D_Description", "#Department"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("iConcurrency", 0, 0, "iConcurrency", "#iConcurrency"), SEP)
            
            .ConfigGrid(grdNum).Request = "exec MKT_UR_Authorised_Users_lst $KEY$, NULL"
            .ConfigGrid(grdNum).Title = "#List of Users To Link"
            .ConfigGrid(grdNum).Tag = "Colored" & SEP & "grd_LinkList"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = True
            .ConfigGrid(grdNum).FetchAll = True
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = False
            .ConfigGrid(grdNum).Load = False
            
            .FaceToolbar = 7
        
        End With
    End With
    
'Master SAME
    ClassInfoNum = ClassInfoNum + 1
    With mt_ClassInfoLst(ClassInfoNum)
        With .ConfigRecord
            .IndexFrame = 8
            .NameFrame = "SAME_Master"
            .IsInit = False
            
            .RequestToApply = "exec MKT_UR_Security_Users_Del $MKT_KEY$,NULL" & SEP & _
                              "exec MKT_UR_Auhtorised_Users_Upd $U_CODE$, '', $SYSTEM_CODE$, $Z_USER$, $ICONCURRENCY$" & SEP & _
                              "exec MKT_UR_Security_Users_Ins $MKT_KEY$, $U_CODE$, $SYSTEM_CODE$"
        End With


'------------------------------------------------
        With .ConfigDetail
            grdNb = 2
            ReDim .ConfigGrid(grdNb)

'------------------------------------------------
            grdNum = 0
            Set .ConfigGrid(grdNum).Grid = grd_Selection(8)
            
            ColNb = 2
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("MKT_Key", 0, 1, "MKT_Key", "#MKT_Key"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("Comp_Desc", 4000, 0, "Comp_Desc", "#Competitor"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_Desc", 4000, 0, "CT_Desc", "#Country"), SEP)
            
            .ConfigGrid(grdNum).Request = "exec MKT_UR_Masters_lst"
            .ConfigGrid(grdNum).Title = "#List of Masters"
            .ConfigGrid(grdNum).Tag = SEP & "grd_Selection"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = True
            .ConfigGrid(grdNum).FetchAll = False
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = False
            .ConfigGrid(grdNum).Load = True

'------------------------------------------------
            grdNum = grdNum + 1
            Set .ConfigGrid(grdNum).Grid = grd_Temp(8)
            
            ColNb = 2
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("MKT_Key", 0, 1, "MKT_Key", "#MKT_Key"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("Comp_Desc", 4000, 0, "Comp_Desc", "#Competitor"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_Desc", 4000, 0, "CT_Desc", "#Country"), SEP)
            
            .ConfigGrid(grdNum).Request = ""
            .ConfigGrid(grdNum).Title = "#Selected Masters"
            .ConfigGrid(grdNum).Tag = "Colored" & SEP & "grd_Temp"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = True
            .ConfigGrid(grdNum).FetchAll = False
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = True
            .ConfigGrid(grdNum).Load = False
            

            
'----------------------------------------------------------
            grdNum = grdNum + 1
            Set .ConfigGrid(grdNum).Grid = grd_LinkList(8)
            
            ColNb = 6
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_code", 0, 1, "U_code", "#U_code"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_First_Name", 1500, 0, "P_First_Name", "#First_Name"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_Name", 1500, 0, "P_Name", "#Surname"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_login_name", 1500, 0, "U_login_name", "#Login ID"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_desc", 1500, 0, "CT_desc", "#Country"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("D_Description", 1500, 0, "D_Description", "#Department"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("iConcurrency", 0, 0, "iConcurrency", "#iConcurrency"), SEP)
            
            .ConfigGrid(grdNum).Request = ""
            .ConfigGrid(grdNum).Title = "#List of Users To Link"
            .ConfigGrid(grdNum).Tag = "Colored" & SEP & "grd_LinkList"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = False
            .ConfigGrid(grdNum).FetchAll = True
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = True
            .ConfigGrid(grdNum).Load = False
            
            .FaceToolbar = 8
        
        End With
    End With
    
    ClassInfoNum = ClassInfoNum + 1
    With mt_ClassInfoLst(ClassInfoNum)
        With .ConfigRecord
            .NameFrame = "DEL_Master"
            
            .RequestToApply = "exec MKT_UR_Security_Users_Del $MKT_KEY$,NULL"
        End With

    End With
    
    
    ClassInfoNum = ClassInfoNum + 1
    With mt_ClassInfoLst(ClassInfoNum)
        With .ConfigRecord
            .NameFrame = "Error"
            .IndexFrame = 9
        End With
        
'------------------------------------------------
        With .ConfigDetail
            grdNb = 0
            ReDim .ConfigGrid(grdNb)

'------------------------------------------------
            grdNum = 0
            Set .ConfigGrid(grdNum).Grid = grd_Error(9)
            
            ColNb = 5
            ReDim .ConfigGrid(grdNum).Columns(ColNb)
            ColNum = 0
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_code", 0, 1, "U_code", "#U_code"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_First_Name", 1500, 0, "#P_First_Name", "#First_Name"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("P_Name", 1500, 0, "P_Name", "#Surname"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("U_login_name", 1500, 0, "#U_login_name", "#Login ID"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("CT_desc", 1500, 0, "CT_desc", "#Country"), SEP)
            ColNum = ColNum + 1
            .ConfigGrid(grdNum).Columns(ColNum) = Join(Array("D_Description", 1500, 0, "D_Description", "#Department"), SEP)
            
            .ConfigGrid(grdNum).Request = ""
            .ConfigGrid(grdNum).Title = "#List of Error"
            .ConfigGrid(grdNum).Tag = SEP & "grd_Error"
            .ConfigGrid(grdNum).AllowExcelExp = True
            .ConfigGrid(grdNum).ExportTitle = True
            .ConfigGrid(grdNum).MultiSel = False
            .ConfigGrid(grdNum).FetchAll = True
            
            .ConfigGrid(grdNum).Enabled = True
            
            .ConfigGrid(grdNum).UnBound = True
            .ConfigGrid(grdNum).Load = False
            
            .FaceToolbar = 9
            
        End With

    End With
    
    
    Exit Sub

errHandler:
    Call ErrorHandler("Load_ClassInfo")

End Sub



Public Sub Load_A_Com()
    
On Error GoTo errHandler


    If mb_Initialized Then Exit Sub
    
    'initialise the temp list to apply to db
    ms_ListSelection = SEP
    ms_ListToLink = SEP
    ms_ListToUnLink = SEP
    
    ms_Errors = SEP

    Call InitComponents
    
    
    Call InitCtrlSize
    Call Load_ClassInfo
    
    ms_Language_Code = "E"
    
    tbs_tab.Visible = True
    tbs_tab.Tabs(1).Selected = True
    
    
    mb_Initialized = True

    
    Exit Sub

errHandler:
    Call ErrorHandler("Load_A_Com")
    
End Sub

Public Sub LoadLabels(ByRef aControls As Variant, ByRef aContainer As Object, ByVal as_ScreenName As String, ByVal as_Language As String)

On Error GoTo errHandler

    Dim lIdx As Long, lCount As Long, lLabels As Long
    Dim lControl As Control
    Dim lv_tag As Variant
    
    
    lLabels = OpenSQLSafe(mo_Db, "exec Screen_Csts '" & as_ScreenName & "','" & as_Language & "'")
    Debug.Assert (lLabels <> 0)
    
    lCount = aControls.Count - 1
    
    For lIdx = 0 To lCount
        Set lControl = aControls.Item(lIdx)
        If HasContainer(lControl, aContainer) Then
        
            Select Case UCase(TypeName(lControl))
                Case "FRAME"
                    lControl.Caption = ""
                    lControl.BorderStyle = 0
                    
                Case "LABEL", "COMMANDBUTTON"
                    If lControl.Tag <> "" Then
                        If mo_Db.Find(lLabels, "FIELD_NAME", lControl.Tag, , 1) >= 0 Then
                            lControl.Caption = mo_Db.GetFields(lLabels, "LOCAL_TEXT")
                        End If
                    End If
                Case "ARMGRID"
                    If mo_Db.Find(lLabels, "FIELD_NAME", lControl.Name & lControl.Index, , 1) >= 0 Then
                        Dim ls_Text As String
                        Dim ll_titleIndex As Long
                        
                        ls_Text = mo_Db.GetFields(lLabels, "LOCAL_TEXT")
                        ll_titleIndex = InStr(1, ls_Text, SEP)
                        
                        If Not lControl.LoadConstants(ptStatic, left(ls_Text, ll_titleIndex - 1) & SEP & "LEFT", ctTopGrid) Then
                            Call Err.Raise(CompFncFailed, "ArmGrid.LoadConstants", "Screen constant error.")
                        End If
                        
                        If Not lControl.LoadConstants(ptStatic, right(ls_Text, Len(ls_Text) - ll_titleIndex - 1), ctColumns) Then
                            Call Err.Raise(CompFncFailed, "ArmGrid.LoadConstants", "Screen constant error.")
                        End If
                    End If
                
                Case "TABSTRIP", "FRAME", "MSFLEXGRID", "TOOLBARCONTROL", "TEXTBOX", "COMMANDBUTTON", "ARMCHECKVIEW", "ARMCOMBOBOX", "A_CALOCX", "OPTIONBUTTON", "ARMTREEVIEW", "LISTBOX", "PICTUREBOX", "TOOLBR", "SPINBUTTON", "OPTIONBUTTON", "CHECKBOX"
                    ' Do nothing !
                Case Else
                    Debug.Print "LoadLabels " & UCase(TypeName(lControl))
            End Select
        End If
        Set lControl = Nothing
    Next
    
    mo_Db.Close (lLabels)

    Exit Sub

errHandler:
    Call ErrorHandler("LoadLabels")
End Sub



Private Sub InitComponents()

On Error GoTo errHandler

    Const CL_REQUEST_TB As String = "SELECT Toolbar_Info FROM Toolbars_Users WHERE User_Code=$user_id$"
    

    Dim ls_Toolbar_Info As String
    Dim lCursTB As Long
    
    'load design toolbars. If you want load user specific toolbars replace 0 for real user id
    lCursTB = OpenSQLSafe(mo_Db, Replace(CL_REQUEST_TB, "$user_id$", 0))
    
    ls_Toolbar_Info = mo_Db.GetFields(lCursTB, "toolbar_info")
    Call mo_Db.Close(lCursTB)
    
    Call tlb_Main.Load_A_Com
    tlb_Main.Language = "E"
    Call tlb_Main.SetToolbarInfoStringParameters(ls_Toolbar_Info, "046")
    
    Call HandleToolbar(tlb_Main, "0", False)
        
    Exit Sub

errHandler:
    mo_Db.Close (lCursTB)
    Call ErrorHandler("InitComponents")
End Sub
Private Sub HandleToolbar(ByVal atlb_Toolbar As Object, ByVal as_face As String, ByVal ab_ButtonsVisible As Boolean)
On Error GoTo errHandler

    atlb_Toolbar.Visible = False
    atlb_Toolbar.DisplayFace (as_face)
    If Not ab_ButtonsVisible Then
        'nothing
    End If
    atlb_Toolbar.Visible = True
    
    Exit Sub
    
errHandler:
    Call ErrorHandler("HandleToolbar")
    
End Sub

Public Sub Unload_A_Com()
On Error GoTo errHandler

    Set mo_Db = Nothing
    
    Exit Sub

errHandler:
    Set mo_Db = Nothing
    Call ErrorHandler("Unload_A_Com")
    
End Sub
' Standard error handler
Private Sub ErrorHandler(ByVal as_Fct As String)
    Call Err.Raise(Err.Number, as_Fct & SEP1 & Err.Source, Err.Description)
End Sub

Private Sub InitCtrlSize()
On Error GoTo errHandler


    Dim lLeft As Long, lTop As Long, lWidth As Long, lHeight As Long
    
    Dim ll_fra_index As Long
    
    lLeft = 100
    lTop = 0
    lWidth = UserControl.Width - lLeft * 2
    Call tlb_Main.Move(lLeft, lTop, lWidth)
    
    lTop = tlb_Main.top + tlb_Main.Height
    Call tbs_tab.Move(lLeft, lTop, lWidth)
    tbs_tab.TabMinWidth = lWidth / 2 - 50
    
    lLeft = 100
    lTop = tbs_tab.top + tbs_tab.Height
    lWidth = UserControl.Width - lLeft * 2
    lHeight = UserControl.Height - lTop
    
    Call fra_frames(0).Move(lLeft, lTop, lWidth, lHeight)
    Call fra_frames(1).Move(lLeft, lTop, lWidth, lHeight)
    Call fra_frames(2).Move(lLeft, lTop, lWidth, lHeight)
    Call fra_frames(3).Move(lLeft, lTop, lWidth, lHeight)
    Call fra_frames(4).Move(lLeft, lTop, lWidth, lHeight)
    Call fra_frames(5).Move(lLeft, lTop, lWidth, lHeight)
    Call fra_frames(6).Move(lLeft, lTop, lWidth, lHeight)
    Call fra_frames(7).Move(lLeft, lTop, lWidth, lHeight)
    Call fra_frames(8).Move(lLeft, lTop, lWidth, lHeight)
    
    Call fra_frames(9).Move(lLeft, lTop, lWidth, lHeight)
    
'Main User
    ll_fra_index = 0 'User Main
    
    lLeft = 100
    lTop = 200
    lWidth = fra_frames(ll_fra_index).Width - lLeft * 2
    lHeight = (fra_frames(ll_fra_index).Height - lTop) / 2 - (50 * 2)
    Call grd_List(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    lTop = grd_List(ll_fra_index).Height + grd_List(ll_fra_index).top + 50
    Call grd_Linked(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    
    
'Main Master
    ll_fra_index = 1 'Main Master

    lLeft = 100
    lTop = 200
    lWidth = fra_frames(ll_fra_index).Width - lLeft * 2
    lHeight = (fra_frames(ll_fra_index).Height - lTop) / 2 - (50 * 2)
    Call grd_List(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    lTop = grd_List(ll_fra_index).Height + grd_List(ll_fra_index).top + 50
    Call grd_Linked(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
     
    
'ADD Users
    ll_fra_index = 2 'ADD User
    
    lLeft = 100
    lTop = 200
    lWidth = fra_frames(ll_fra_index).Width - lLeft * 2
    lHeight = (fra_frames(ll_fra_index).Height - lTop) / 3 - 50 * 4
    Call grd_Selection(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    
    lLeft = 100
    lTop = grd_Selection(ll_fra_index).top + grd_Selection(ll_fra_index).Height + 50
    Call grd_Temp(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    
    lTop = grd_Temp(ll_fra_index).top + grd_Temp(ll_fra_index).Height + 100
    Call lbl_labels(ll_fra_index).Move(lLeft, lTop)
    
    lLeft = lbl_labels(ll_fra_index).Width + 20 + 100
    Call chk_StratCountry(ll_fra_index).Move(lLeft, lTop)
    

    lLeft = 100
    lTop = chk_StratCountry(ll_fra_index).top + chk_StratCountry(ll_fra_index).Height + 30
    lHeight = fra_frames(ll_fra_index).Height - (lTop + 50)
    Call Fra_SubFrames(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    
    lLeft = 0
    lTop = 100
    lWidth = (Fra_SubFrames(ll_fra_index).Width / 2) - 200 - btn_AddSel(ll_fra_index).Width / 2
    lHeight = Fra_SubFrames(ll_fra_index).Height - lTop * 2
    Call grd_AvailList(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    
    lLeft = grd_AvailList(ll_fra_index).Width + 200 + btn_AddSel(2).Width
    lWidth = grd_AvailList(ll_fra_index).Width
    lHeight = grd_AvailList(ll_fra_index).Height
    Call grd_LinkList(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
   
    lLeft = grd_AvailList(ll_fra_index).Width + 100
    lTop = Fra_SubFrames(ll_fra_index).Height / 2 - btn_AddSel(ll_fra_index).Width - 100
    Call btn_AddSel(ll_fra_index).Move(lLeft, lTop)
    
    lTop = btn_AddSel(ll_fra_index).top + btn_AddSel(ll_fra_index).Height + 100
    Call btn_DelSel(ll_fra_index).Move(lLeft, lTop)
    
'DEL USER
    ll_fra_index = 3 'DEL User

    lLeft = 100
    lTop = 200
    lWidth = fra_frames(ll_fra_index).Width - lLeft * 2
    lHeight = (fra_frames(ll_fra_index).Height - lTop) / 2 - (50 * 2)
    Call grd_Selection(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    lTop = grd_Selection(ll_fra_index).Height + grd_Selection(ll_fra_index).top + 50
    Call grd_Temp(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    
'UPD Users
    
    ll_fra_index = 4 'UPD User
    
    lLeft = 100
    lTop = 200
    lWidth = fra_frames(ll_fra_index).Width - lLeft * 2
    lHeight = fra_frames(ll_fra_index).Height / 3 - 50 * 4
    Call grd_Temp(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    
    lTop = grd_Temp(ll_fra_index).top + grd_Temp(ll_fra_index).Height + 100
    Call lbl_labels(ll_fra_index).Move(lLeft, lTop)
    
    lLeft = lbl_labels(ll_fra_index).Width + 20 + 100
    Call chk_StratCountry(ll_fra_index).Move(lLeft, lTop)
    

    lLeft = 100
    lTop = chk_StratCountry(ll_fra_index).top + chk_StratCountry(ll_fra_index).Height + 30
    lHeight = fra_frames(ll_fra_index).Height - (lTop + 50)
    Call Fra_SubFrames(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    
    lLeft = 0
    lTop = 100
    lWidth = (Fra_SubFrames(ll_fra_index).Width / 2) - 200 - btn_AddSel(ll_fra_index).Width / 2
    lHeight = Fra_SubFrames(ll_fra_index).Height - lTop * 2
    Call grd_AvailList(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    
    lLeft = grd_AvailList(ll_fra_index).Width + 200 + btn_AddSel(ll_fra_index).Width
    lWidth = grd_AvailList(ll_fra_index).Width
    lHeight = grd_AvailList(ll_fra_index).Height
    Call grd_LinkList(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
   
    lLeft = grd_AvailList(ll_fra_index).Width + 100
    lTop = Fra_SubFrames(ll_fra_index).Height / 2 - btn_AddSel(ll_fra_index).Width - 100
    Call btn_AddSel(ll_fra_index).Move(lLeft, lTop)
    
    lTop = btn_AddSel(ll_fra_index).top + btn_AddSel(ll_fra_index).Height + 100
    Call btn_DelSel(ll_fra_index).Move(lLeft, lTop)
    
    
'SAME User
    ll_fra_index = 5 'SAME User


    lLeft = 100
    lTop = 200
    lWidth = fra_frames(ll_fra_index).Width - lLeft * 2
    lHeight = fra_frames(ll_fra_index).Height / 3 - 50 * 4
    Call grd_Selection(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    
    lLeft = 100
    lTop = grd_Selection(ll_fra_index).top + grd_Selection(ll_fra_index).Height + 100
    Call grd_Temp(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
       

    lLeft = 100
    lTop = grd_Temp(ll_fra_index).top + grd_Temp(ll_fra_index).Height + 30
    lHeight = fra_frames(ll_fra_index).Height - (lTop + 50)
    Call Fra_SubFrames(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    
    lLeft = 100
    lTop = 100
    lWidth = (Fra_SubFrames(ll_fra_index).Width / 2) - 200
    lHeight = Fra_SubFrames(ll_fra_index).Height - lTop * 2
    Call grd_LinkList(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
   
'CPY Users
    ll_fra_index = 6 'CPY User

    lLeft = 100
    lTop = 200
    lWidth = fra_frames(ll_fra_index).Width - lLeft * 2
    lHeight = fra_frames(ll_fra_index).Height / 3 - 50 * 4
    Call grd_Selection(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    
    lLeft = 100
    lTop = grd_Selection(ll_fra_index).top + grd_Selection(ll_fra_index).Height + 100
    Call grd_Temp(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    
    lLeft = 100
    lTop = grd_Temp(ll_fra_index).top + grd_Temp(ll_fra_index).Height + 30
    lHeight = fra_frames(ll_fra_index).Height - (lTop + 50)
    Call Fra_SubFrames(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    
    lLeft = 0
    lTop = 100
    lWidth = (Fra_SubFrames(ll_fra_index).Width / 2) - 200
    lHeight = Fra_SubFrames(ll_fra_index).Height - lTop * 2
    Call grd_AvailList(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    
    lLeft = grd_AvailList(ll_fra_index).Width + 200
    lWidth = grd_AvailList(ll_fra_index).Width
    lHeight = grd_AvailList(ll_fra_index).Height
    Call grd_LinkList(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
   
'UPD Master
    ll_fra_index = 7 'UPD Master
    
    lLeft = 100
    lTop = 200
    lWidth = fra_frames(ll_fra_index).Width - lLeft * 2
    lHeight = fra_frames(ll_fra_index).Height / 3 - 50 * 4
    Call grd_Temp(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    

    lLeft = 100
    lTop = grd_Temp(ll_fra_index).top + grd_Temp(ll_fra_index).Height + 30
    lHeight = fra_frames(ll_fra_index).Height - (lTop + 50)
    Call Fra_SubFrames(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    
    lLeft = 0
    lTop = 100
    lWidth = (Fra_SubFrames(ll_fra_index).Width / 2) - 200 - btn_AddSel(ll_fra_index).Width / 2
    lHeight = Fra_SubFrames(ll_fra_index).Height - lTop * 2
    Call grd_AvailList(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    
    lLeft = grd_AvailList(ll_fra_index).Width + 200 + btn_AddSel(ll_fra_index).Width
    lWidth = grd_AvailList(ll_fra_index).Width
    lHeight = grd_AvailList(ll_fra_index).Height
    Call grd_LinkList(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
   
    lLeft = grd_AvailList(ll_fra_index).Width + 100
    lTop = Fra_SubFrames(ll_fra_index).Height / 2 - btn_AddSel(ll_fra_index).Width - 100
    Call btn_AddSel(ll_fra_index).Move(lLeft, lTop)
    
    lTop = btn_AddSel(ll_fra_index).top + btn_AddSel(ll_fra_index).Height + 100
    Call btn_DelSel(ll_fra_index).Move(lLeft, lTop)
 

'SAME Master
    ll_fra_index = 8 'SAME Master

    lLeft = 100
    lTop = 200
    lWidth = fra_frames(ll_fra_index).Width - lLeft * 2
    lHeight = fra_frames(ll_fra_index).Height / 3 - 50 * 4
    Call grd_Selection(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    
    lLeft = 100
    lTop = grd_Selection(ll_fra_index).top + grd_Selection(ll_fra_index).Height + 100
    Call grd_Temp(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
       

    lLeft = 100
    lTop = grd_Temp(ll_fra_index).top + grd_Temp(ll_fra_index).Height + 30
    lHeight = fra_frames(ll_fra_index).Height - (lTop + 50)
    Call Fra_SubFrames(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
    
    lLeft = 0
    lTop = 100
    lWidth = (Fra_SubFrames(ll_fra_index).Width / 2) - 200
    lHeight = Fra_SubFrames(ll_fra_index).Height - lTop * 2
    Call grd_LinkList(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
   
   
'error
    ll_fra_index = 9 'ERROR
    
    lLeft = 50
    lTop = 100
    lWidth = fra_frames(ll_fra_index).Width - 50 * 2
    lHeight = fra_frames(ll_fra_index).Height / 3 - 50 * 4
    Call grd_Error(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
       
    lLeft = 100
    lTop = lbl_labels(ll_fra_index).top + lbl_labels(ll_fra_index).Height
    lWidth = fra_frames(ll_fra_index).Width - 50 * 2
    lHeight = fra_frames(ll_fra_index).Height / 3 - 50 * 4
    Call grd_Error(ll_fra_index).Move(lLeft, lTop, lWidth, lHeight)
   
   Exit Sub

errHandler:
    Call ErrorHandler("InitCtrlSize")
End Sub




' Return the result of a SQL request
' Convert SQL runtime errors and process errors to VB Error
#If LIVE = 1 Then
Private Function OpenSQLSafe(ByVal ao_Db As Object, ByVal as_Request As String, Optional ByVal al_RowExpectedCount = -1) As Long
#Else
Private Function OpenSQLSafe(ByVal ao_Db As ARMSYSCOMLib.ArmDb, ByVal as_Request As String, Optional ByVal al_RowExpectedCount = -1) As Long
#End If

On Error GoTo errHandler

    Dim lc_Data As Long
    lc_Data = ao_Db.OpenSQL(as_Request)
    
    If lc_Data = 0 Then
        Err.Raise ArmErr.SQLFailure, "SQL : " & as_Request, Join(ao_Db.SQLErrorCodes, SEP2) & SEP1 & Join(ao_Db.SQLErrorMessages, SEP2)
    End If
'    Debug.Print 1 / 0
    If al_RowExpectedCount <> -1 Then
        ' Then check the rowcount
        If ao_Db.RowCount(lc_Data) <> al_RowExpectedCount Then
            Err.Raise ArmErr.SQLBadRowExpectedCount, "SQL : " & as_Request, al_RowExpectedCount & "<>" & ao_Db.RowCount(lc_Data)
        End If
    End If

    OpenSQLSafe = lc_Data

    Exit Function

errHandler:

    Call ErrorHandler("OpenSQLSafe")

End Function

' Execute a SQL request returning no data
' Convert SQL runtime errors and process errors to VB Error
' Params:
' ao_Db (Object)
' as_Request (String)
' al_RowAffectedCount (String)
#If LIVE = 1 Then
Private Sub ExecuteSQLSafe(ByVal ao_Db As Object, ByVal as_Request As String, Optional ByVal al_RowAffectedCount = -1, Optional ab_DuplicityCheck As Boolean = False)
#Else
Private Sub ExecuteSQLSafe(ByVal ao_Db As ARMSYSCOMLib.ArmDb, ByVal as_Request As String, Optional ByVal al_RowAffectedCount = -1, Optional ab_DuplicityCheck As Boolean = False)
#End If
On Error GoTo errHandler

    ' First execute the request
    If Not ao_Db.ExecuteSQL(as_Request) Then
        Err.Raise ArmErr.SQLFailure, "SQL : " & as_Request, Join(ao_Db.SQLErrorCodes, SEP2) & SEP1 & Join(ao_Db.SQLErrorMessages, SEP2)
    End If

    If al_RowAffectedCount <> -1 Then
        ' Then check the rowcount
        If ao_Db.SQLRowsAffected <> al_RowAffectedCount Then
            
            If ab_DuplicityCheck Then
                Err.Raise ArmCusErr.DuplicityDetected, "SQL : " & as_Request, al_RowAffectedCount & "<>" & ao_Db.SQLRowsAffected
            Else
                Err.Raise ArmErr.SQLBadRowAffectedCount, "SQL : " & as_Request, al_RowAffectedCount & "<>" & ao_Db.SQLRowsAffected
            End If
        End If
    End If

    Exit Sub

errHandler:
    Call ErrorHandler("ExecuteSQLSafe")
End Sub
Private Sub LockScreen(ByVal ab_lock As Boolean)

    Dim ll_errNumber As Long, ls_ErrSrc As String, ls_ErrDesc As String
    ll_errNumber = Err.Number
    ls_ErrSrc = Err.Source
    ls_ErrDesc = Err.Description

On Error GoTo errHandler
    Static ll_Count As Long
    Static ll_Mousepointer As Long
    Static lb_Locked As Boolean
      
      
    ll_Count = ll_Count + IIf(ab_lock, 1, -1)
    Debug.Assert (ll_Count >= 0)
    
    ' First lock
    If Not lb_Locked And ab_lock Then
        ll_Mousepointer = Screen.MousePointer
        Screen.MousePointer = vbHourglass
        LockWindowUpdate UserControl.hwnd
        lb_Locked = True
    End If
    
    ' Unlock
    If ll_Count = 0 Then
        DoEvents ' Flush events
        LockWindowUpdate 0
        UserControl.Refresh ' Repaint immediately
        Screen.MousePointer = ll_Mousepointer
        lb_Locked = False
    End If
    
    Err.Number = ll_errNumber
    Err.Source = ls_ErrSrc
    Err.Description = ls_ErrDesc
    
    Exit Sub
    
errHandler:
    Call ErrorHandler("LockScreen")

End Sub


Private Sub btn_AddSel_Click(Index As Integer)
    Call LockScreen(True)
    Call AddLineToGrid(grd_AvailList(Index), grd_LinkList(Index), ms_ListToLink, ms_ListToUnLink, True)
    Call LockScreen(False)
End Sub

Private Sub btn_DelSel_Click(Index As Integer)
    Call LockScreen(True)
    Call AddLineToGrid(grd_LinkList(Index), grd_AvailList(Index), ms_ListToLink, ms_ListToUnLink, True)
    Call LockScreen(False)
End Sub

Private Sub chk_StratCountry_Click(Index As Integer)
    Call LockScreen(True)
    Fra_SubFrames(Index).Visible = Not chk_StratCountry(Index).value
    Call LockScreen(False)
End Sub


Private Sub grd_AvailList_Click(Index As Integer)

Dim ls_Request As String
    
    Call LockScreen(True)

    grd_LinkList(Index).DeselectRow
    
    If Index = 6 Then
        If grd_AvailList(Index).SelectedCount = 0 Then
            grd_LinkList(Index).ClearGrid
            GoTo ExitNow
        Else
            ms_ListToLink = SEP
            ls_Request = grd_LinkList(Index).Requests(0)
            grd_LinkList(Index).Requests = Replace(ls_Request, "$KEY$", grd_AvailList(Index).SelectedLine(0, 0))
            If grd_LinkList(Index).Execute = False Then
                Debug.Print "grd_AvailList_Click -> Execute request grid error"
            End If
            grd_LinkList(Index).Requests = ls_Request
        End If
    End If
ExitNow:
    Call LockScreen(False)
    
End Sub

Private Sub grd_AvailList_DblClick(Index As Integer)
    If Index <> 6 Then
        Call LockScreen(True)
        Call AddLineToGrid(grd_AvailList(Index), grd_LinkList(Index), ms_ListToLink, ms_ListToUnLink, True)
        Call LockScreen(False)
    End If
End Sub

Private Sub grd_AvailList_SelChange(Index As Integer)
    Call LockScreen(True)
    Call grd_AvailList_Click(Index)
    Call LockScreen(False)
End Sub

Private Sub grd_LinkList_Click(Index As Integer)
    If Index <> 5 And Index <> 6 And Index <> 8 Then
        Call LockScreen(True)
        grd_AvailList(Index).DeselectRow
        Call LockScreen(False)
    End If
End Sub

Private Sub grd_LinkList_DblClick(Index As Integer)
    If Index <> 5 And Index <> 6 And Index <> 8 Then
        Call LockScreen(True)
        Call AddLineToGrid(grd_LinkList(Index), grd_AvailList(Index), ms_ListToLink, ms_ListToUnLink, True)
        Call LockScreen(False)
    End If
End Sub

Private Sub grd_LinkList_RowLoaded(Index As Integer, ByVal al_Row As Long)
    
    grd_LinkList(Index).LineColor(al_Row) = vbYellow
    If Index = 6 Then
        ms_ListToLink = ms_ListToLink & grd_LinkList(Index).Data(al_Row, 0) & SEP
    End If
    
End Sub

Private Sub grd_List_SelChange(Index As Integer)

On Error GoTo errHandler

    Dim ls_Request As String
    Call LockScreen(True)
    
    If grd_List(Index).SelectedCount = 0 Then
        grd_Linked(Index).ClearGrid
        GoTo ExitNow
    End If
    
    If Index = 0 And grd_List(Index).SelectedLine(0, "Strat_Country") = "X" Then
        grd_Linked(Index).ClearGrid
    Else
        ls_Request = grd_Linked(Index).Requests(0)
        grd_Linked(Index).Requests = Replace(ls_Request, "$KEY$", grd_List(Index).SelectedKey(0)(0), , , vbTextCompare)
        grd_Linked(Index).Execute
        
        grd_Linked(Index).Requests = ls_Request
    End If
ExitNow:
    Call LockScreen(False)
    
    Exit Sub
errHandler:
    Call LockScreen(False)
    Call ErrorHandler("grd_List_SelChange")
    
End Sub



Private Sub grd_Selection_Click(Index As Integer)
    grd_Temp(Index).DeselectRow
End Sub

Private Sub grd_Selection_DblClick(Index As Integer)
    Call LockScreen(True)
    Call AddLineToGrid(grd_Selection(Index), grd_Temp(Index), ms_ListSelection, "", True)
    Call LockScreen(False)
End Sub

Private Sub AddLineToGrid(ByVal grd_source As ArmGrid, ByVal grd_destination As ArmGrid, ByRef as_ListLink As String, ByRef as_ListUnlink As String, ByVal lb_WithDelLines As Boolean)
On Error GoTo errHandler
    Dim ll_nbline As Long
    Dim ll_Idx As Long
    Dim ll_ColIdx As Long
    Dim lv_newRow As Variant
    Dim lb_color As Boolean
    
    If grd_destination.TagVariant Like "Colored*" Then
        lb_color = True
    End If
    
    ll_nbline = grd_source.SelectedCount - 1
    ReDim lv_newRow(grd_destination.Cols - 1)
    
    For ll_Idx = 0 To ll_nbline
        For ll_ColIdx = 0 To grd_destination.Cols - 1
            lv_newRow(ll_ColIdx) = grd_source.SelectedLine(ll_Idx, grd_destination.Columns(ll_ColIdx).Name)
        Next ll_ColIdx
        Call grd_destination.AddLine(lv_newRow)
        
        If lb_color Then
            grd_destination.LineColor(grd_destination.Rows - 1) = vbYellow
            If InStr(1, as_ListUnlink, SEP & grd_destination.SelectedLine(0, 0) & SEP, vbTextCompare) Then
                as_ListUnlink = Replace(as_ListUnlink, SEP & grd_destination.SelectedLine(0, 0) & SEP, SEP, , , vbTextCompare)
            Else
                as_ListLink = as_ListLink & grd_destination.SelectedLine(0, 0) & SEP
            End If
        Else
            If InStr(1, as_ListLink, SEP & grd_destination.SelectedLine(0, 0) & SEP, vbTextCompare) Then
                as_ListLink = Replace(as_ListLink, SEP & grd_destination.SelectedLine(0, 0) & SEP, SEP, , , vbTextCompare)
            Else
                as_ListUnlink = as_ListUnlink & grd_destination.SelectedLine(0, 0) & SEP
            End If
        End If
        
    Next ll_Idx
    
    If lb_WithDelLines Then
        grd_source.DeleteSelectedLines
    End If
    
    Exit Sub
    
errHandler:
    Call ErrorHandler("AddLineToGrid")
    
End Sub


Private Sub grd_Temp_Click(Index As Integer)
    grd_Selection(Index).DeselectRow
End Sub

Private Sub grd_Temp_DblClick(Index As Integer)
    Call LockScreen(True)
    Call AddLineToGrid(grd_Temp(Index), grd_Selection(Index), ms_ListSelection, "", True)
    Call LockScreen(False)
End Sub

Private Sub grd_Temp_RowLoaded(Index As Integer, ByVal al_Row As Long)
    grd_Temp(Index).LineColor(al_Row) = vbYellow
End Sub



Private Sub tbs_tab_Click()
On Error GoTo errHandler
    
    Call LockScreen(True)
    
    Dim ll_Interf_Index As Long
    
    
    ll_Interf_Index = tbs_tab.SelectedItem.Tag
    
    ml_AcitveClassIndex = ll_Interf_Index
    
    Call DisplayScreen(ll_Interf_Index, False)
    
    tbs_tab.Enabled = True
    
    Call LockScreen(False)
    
    Exit Sub
errHandler:
    Call LockScreen(False)

    Call ErrorHandler("tbs_tab_Click()")
End Sub
Private Sub InitializedDetailGrid(ByVal ao_grid As ArmGrid, ByVal al_InfoArrayIndex As Long, ByVal al_GridIndex As Long)
On Error GoTo errHandler
    Dim ls_gridRequest As String
    
    Set ao_grid.ArmDb = mo_Db
    ao_grid.Load_A_Com
    

    
    ao_grid.AllowExcelExport = mt_ClassInfoLst(al_InfoArrayIndex).ConfigDetail.ConfigGrid(al_GridIndex).AllowExcelExp
    ao_grid.ExportTitles = mt_ClassInfoLst(al_InfoArrayIndex).ConfigDetail.ConfigGrid(al_GridIndex).ExportTitle
    ao_grid.MultiSelect = mt_ClassInfoLst(al_InfoArrayIndex).ConfigDetail.ConfigGrid(al_GridIndex).MultiSel
    ao_grid.FetchAll = mt_ClassInfoLst(al_InfoArrayIndex).ConfigDetail.ConfigGrid(al_GridIndex).FetchAll
    ao_grid.UnBound = mt_ClassInfoLst(al_InfoArrayIndex).ConfigDetail.ConfigGrid(al_GridIndex).UnBound
    ao_grid.Title = mt_ClassInfoLst(al_InfoArrayIndex).ConfigDetail.ConfigGrid(al_GridIndex).Title
    ao_grid.TagVariant = mt_ClassInfoLst(al_InfoArrayIndex).ConfigDetail.ConfigGrid(al_GridIndex).Tag
    ao_grid.Enabled = mt_ClassInfoLst(al_InfoArrayIndex).ConfigDetail.ConfigGrid(al_GridIndex).Enabled
   
   
    ls_gridRequest = mt_ClassInfoLst(al_InfoArrayIndex).ConfigDetail.ConfigGrid(al_GridIndex).Request
    
    ao_grid.ClearGrid

    If Not ao_grid.SetColumns(mt_ClassInfoLst(al_InfoArrayIndex).ConfigDetail.ConfigGrid(al_GridIndex).Columns) Then
        Debug.Print " InitializedDetailGrid -> SetColumns error"
        Call Unload_A_Com
        End
    End If

    Call ao_grid.LoadConstants(ptStatic, mt_ClassInfoLst(al_InfoArrayIndex).ConfigDetail.ConfigGrid(al_GridIndex).Labels, ctColumns)
    ao_grid.Requests = ls_gridRequest
    If mt_ClassInfoLst(al_InfoArrayIndex).ConfigDetail.ConfigGrid(al_GridIndex).Load = True Then
        If ao_grid.Execute = False Then
            Debug.Print " InitializedDetailGrid -> " & ao_grid.Title & " - Execute request grid error"
        End If
    End If
    
    
    Exit Sub
errHandler:
    Call ErrorHandler("InitializedDetailGrid")

End Sub

Private Sub LoadFrame(ByVal al_ClassIndex As Long)
On Error GoTo errHandler
    
    Dim ll_IndexFrame As Long
    
    ll_IndexFrame = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IndexFrame
    
    Dim i As Integer
    For i = 0 To UBound(mt_ClassInfoLst(al_ClassIndex).ConfigDetail.ConfigGrid)
        Call InitializedDetailGrid(mt_ClassInfoLst(al_ClassIndex).ConfigDetail.ConfigGrid(i).Grid, al_ClassIndex, i)
        Call LoadLabels(UserControl.Controls, fra_frames(ll_IndexFrame), SCREEN_NAME, ms_Language_Code)
    Next i
    
    mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IsInit = True
    Exit Sub
    
errHandler:
    Call ErrorHandler("LoadFrame")

End Sub

Private Sub DisplayScreen(ByVal al_ClassIndex As Long, ByVal lb_WithFullRefresh As Boolean)
On Error GoTo errHandler
    Dim fra_index As Long
    Dim ll_IndexFrame As Long
    
    ll_IndexFrame = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IndexFrame
    
    tlb_Main.Visible = True
    tlb_Main.ZOrder
    Call HandleToolbar(tlb_Main, mt_ClassInfoLst(al_ClassIndex).ConfigDetail.FaceToolbar, False)
            
    If Not mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IsInit Then
        Call LoadFrame(al_ClassIndex)
    Else
        If lb_WithFullRefresh Then
            Call ClearFrame(UserControl.Controls, fra_frames(ll_IndexFrame))
        End If
    End If
    
    ms_ListSelection = SEP
    ms_ListToLink = SEP
    ms_ListToUnLink = SEP
    
    fra_frames(ll_IndexFrame).Visible = True
    fra_frames(ll_IndexFrame).ZOrder
    Exit Sub
    
errHandler:
    Call ErrorHandler("DisplayScreen")

End Sub
Private Sub ClearFrame(ByRef aControls As Variant, ByRef aContainer As Object)
On Error GoTo errHandler
    'mb_internal = True
    
    Dim lIdx As Long, lCount As Long, lControl As Object
    lCount = aControls.Count - 1
    For lIdx = 0 To lCount
        Set lControl = aControls.Item(lIdx)
        If HasContainer(lControl, aContainer) Then
            Select Case UCase(TypeName(lControl))
                Case "CHECKBOX"
                    lControl.value = vbUnchecked
                
                Case "ARMGRID"
                    If lControl.UnBound = True Then
                        lControl.ClearGrid
                    Else
                        lControl.Refresh
                    End If
                
                Case Else
                    Debug.Print "ClearFrame " & UCase(TypeName(lControl))
            End Select
        End If
        
        Set lControl = Nothing
    Next
    
    Exit Sub
    
errHandler:
    If (Not lControl Is Nothing) Then Set lControl = Nothing
    Call ErrorHandler("ClearFrame")

End Sub


Private Function HasContainer(ByRef aControl As Control, ByRef aContainer As Object) As Boolean
    
    HasContainer = False
    Dim lControl As Control
    
    Set lControl = aControl
    While Not (lControl Is Nothing)
        On Error GoTo NotFound
        If lControl.Container Is aContainer Then
            Set lControl = Nothing
            HasContainer = True
            Exit Function
        End If
        Set lControl = lControl.Container
    Wend

NotFound:
    Set lControl = Nothing
    HasContainer = False
End Function
Private Function ReplaceHolders(ByRef aControls As Variant, ByRef aContainer As Object, ByVal as_Request As String) As String
    
On Error GoTo errHandler

    Dim lIdx As Long, lCount As Long
    Dim lControl As Control
    Dim lv_number As Variant
    Dim lValues As Variant
    
    
    lCount = aControls.Count - 1
    
    For lIdx = 0 To lCount
        Set lControl = aControls.Item(lIdx)
        If HasContainer(lControl, aContainer) Then
            Select Case UCase(TypeName(lControl))
                
                Case "CHECKBOX"
                  lValues = Split(UCase(lControl.Tag), SEP)
                  If lControl.value = True Then
                    as_Request = Replace(as_Request, "$" & lValues(0) & "$", "X", , , vbTextCompare)
                  Else
                    as_Request = Replace(as_Request, "$" & lValues(0) & "$", "", , , vbTextCompare)
                  End If
            
            End Select
        End If
        Set lControl = Nothing
    Next
    
    as_Request = Replace(as_Request, "$SYSTEM_CODE$", SYSTEM_CODE, , , vbTextCompare)
    as_Request = Replace(as_Request, "$Z_USER$", ml_U_code, , , vbTextCompare)
    
    ReplaceHolders = as_Request
    Exit Function
    
errHandler:
    If Not lControl Is Nothing Then Set lControl = Nothing
    Call ErrorHandler("ReplaceHolders")
    
End Function
Private Sub ApplyChangesDEL_Master(ByVal al_ClassIndex As Long)
On Error GoTo errHandler
    Dim ll_IndexFrame As Long
       
    If grd_List(tbs_tab.SelectedItem.Tag).SelectedCount = 0 Then
        Exit Sub
    End If

    If MsgBox("#Do you really want to delete all the users linked to the selected master?", vbQuestion + vbYesNo + vbDefaultButton2) = vbNo Then
        Call ExitToMain(False)
        Exit Sub
    End If
    
    Call ApplyChangesDB_DEL_Master(al_ClassIndex)
    
    Call ExitToMain(True)
    
    Exit Sub
    
errHandler:
    Call ErrorHandler("ApplyChangesDEL_Master")
    
End Sub


Private Sub ApplyChangesADD(ByVal al_ClassIndex As Long)
On Error GoTo errHandler
    Dim ll_IndexFrame As Long
    
    ll_IndexFrame = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IndexFrame
    


    If ms_ListSelection = SEP Then
        MsgBox "You must selection something in the grid " & grd_Temp(ll_IndexFrame).Title, vbInformation
        Exit Sub
    End If
    
   
    If ms_ListToLink = SEP And chk_StratCountry(ll_IndexFrame).value = False Then
        MsgBox "You must selection something in the grid " & grd_LinkList(ll_IndexFrame).Title, vbInformation
        Exit Sub
    End If
    
    Call ApplyChangesDB_ADD(al_ClassIndex)
    
    Call ExitToMain(True)
    
    Exit Sub
    
errHandler:
    Call ErrorHandler("ApplyChangesADD")
    
End Sub
Private Sub ApplyChangesCPY(ByVal al_ClassIndex As Long)
On Error GoTo errHandler
    Dim ll_IndexFrame As Long
    
    ll_IndexFrame = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IndexFrame
    If ms_ListSelection = SEP Then
        MsgBox "You must selection something in the grid " & grd_Temp(ll_IndexFrame).Title, vbInformation
        Exit Sub
    End If
    
   
    If ms_ListToLink = SEP Then
        MsgBox "You must selection something in the grid " & grd_LinkList(ll_IndexFrame).Title, vbInformation
        Exit Sub
    End If
    
    Call ApplyChangesDB_ADD(al_ClassIndex)
    
    Call ExitToMain(True)
    
    Exit Sub
    
errHandler:
    Call ErrorHandler("ApplyChangesCPY")
    
End Sub
Private Sub ApplyChangesSAME_User(ByVal al_ClassIndex As Long)
On Error GoTo errHandler
    Dim ll_IndexFrame As Long
    
    ll_IndexFrame = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IndexFrame

    If ms_ListSelection = SEP Then
        MsgBox "You must selection something in the grid " & grd_Temp(ll_IndexFrame).Title, vbInformation
        Exit Sub
    End If
        
    Call ApplyChangesDB_SAME_User(al_ClassIndex)
    
    Call ExitToMain(True)
    
    Exit Sub
    
errHandler:
    Call ErrorHandler("ApplyChangesSAME_User")
    
End Sub


Private Sub ApplyChangesSAME_Master(ByVal al_ClassIndex As Long)
On Error GoTo errHandler
    Dim ll_IndexFrame As Long
    
    ll_IndexFrame = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IndexFrame

    If ms_ListSelection = SEP Then
        MsgBox "You must selection something in the grid " & grd_Temp(ll_IndexFrame).Title, vbInformation
        Exit Sub
    End If
        
    Call ApplyChangesDB_SAME_Master(al_ClassIndex)
    
    Call ExitToMain(True)
    
    Exit Sub
    
errHandler:
    Call ErrorHandler("ApplyChangesSAME_Master")
    
End Sub


Private Sub ApplyChangesUPD_User(ByVal al_ClassIndex As Long)
On Error GoTo errHandler
    Dim ll_IndexFrame As Long
    Dim ll_IndexFrame2 As Long
    
    ll_IndexFrame = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IndexFrame
    
    If ms_ListToLink = SEP And ms_ListToUnLink = SEP And chk_StratCountry(ll_IndexFrame).value = False Then
        ExitToMain (False)
        Exit Sub
    End If
    
       
    If grd_LinkList(ll_IndexFrame).Rows = 0 And chk_StratCountry(ll_IndexFrame).value = False Then
        MsgBox "You must selection something in the grid " & grd_LinkList(ll_IndexFrame).Title, vbInformation
        Exit Sub
    End If
    
    Call ApplyChangesDB_UPD_User(al_ClassIndex)
    
    If ms_Errors <> SEP Then
        Call ExitToMain(False)
        Exit Sub
    End If
    
    If chk_StratCountry(ll_IndexFrame).value = False Then
        If MsgBox("Would you like to apply the same masters to other users?", vbYesNo + vbDefaultButton2, "") = vbYes Then
            ml_AcitveClassIndex = 5
            Call DisplayScreen(ml_AcitveClassIndex, True)
            ll_IndexFrame2 = mt_ClassInfoLst(ml_AcitveClassIndex).ConfigRecord.IndexFrame
            Call CopyGrid(grd_LinkList(ll_IndexFrame), grd_LinkList(ll_IndexFrame2), ms_ListToLink)
            If grd_Selection(ll_IndexFrame2).SearchKey(True, grd_List(tbs_tab.SelectedItem.Tag).SelectedLine(0, 0)) Then
                grd_Selection(ll_IndexFrame2).DeleteLine
                grd_Selection(ll_IndexFrame2).FirstLine
                grd_Selection(ll_IndexFrame2).DeselectRow
            End If
        Else
            Call ExitToMain(True)
        End If
    Else
        Call ExitToMain(True)
    End If
        
    Exit Sub
    
errHandler:
    Call ErrorHandler("ApplyChangesUPD_User")
    
End Sub
Private Sub ApplyChangesUPD_Master(ByVal al_ClassIndex As Long)
On Error GoTo errHandler
    Dim ll_IndexFrame As Long
    Dim ll_IndexFrame2 As Long
    
    If ms_ListToLink = SEP And ms_ListToUnLink = SEP Then
        Call ExitToMain(False)
        Exit Sub
    End If
    
    ll_IndexFrame = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IndexFrame
       
    Call ApplyChangesDB_UPD_Master(al_ClassIndex)
    
    If ms_Errors <> SEP Then
        Call ExitToMain(True)
        Exit Sub
    End If
    
    
    If MsgBox("Would you like to apply the same users to other masters?", vbYesNo + vbDefaultButton2, "") = vbYes Then
        ml_AcitveClassIndex = 8
        Call DisplayScreen(ml_AcitveClassIndex, True)
        ll_IndexFrame2 = mt_ClassInfoLst(ml_AcitveClassIndex).ConfigRecord.IndexFrame
        Call CopyGrid(grd_LinkList(ll_IndexFrame), grd_LinkList(ll_IndexFrame2), ms_ListToLink)
        If grd_Selection(ll_IndexFrame2).SearchKey(True, grd_List(tbs_tab.SelectedItem.Tag).SelectedLine(0, 0)) Then
            grd_Selection(ll_IndexFrame2).DeleteLine
            grd_Selection(ll_IndexFrame2).FirstLine
            grd_Selection(ll_IndexFrame2).DeselectRow
        End If
    Else
        Call ExitToMain(True)
    End If

    Exit Sub
    
errHandler:
    Call ErrorHandler("ApplyChangesUPD_Master")
    
End Sub


Private Sub ApplyChangesDB_ADD(ByVal al_ClassIndex As Long)
On Error GoTo errHandler
    
    Dim lv_req As Variant
    Dim ls_Req As String

    Dim lv_Selection As Variant
    Dim lv_ToLink As Variant
    
    Dim ls_HolderSel As String
    Dim ls_HolderLink As String
    
    Dim lb_TranOpened As Boolean
    
    Dim ll_IndexFrame As Long
    
    ll_IndexFrame = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IndexFrame
    
    ls_HolderSel = UCase(grd_Temp(ll_IndexFrame).Columns(0).Name)
    
    ls_Req = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.RequestToApply
    
    If InStr(1, ls_Req, "$STRAT_COUNTRY$", vbTextCompare) Then
        If chk_StratCountry(ll_IndexFrame).value = True Then
            ms_ListToLink = SEP
            ms_ListToUnLink = SEP
        End If
    End If
    
    
    ls_Req = ReplaceHolders(UserControl.Controls, fra_frames(ll_IndexFrame), ls_Req)
    lv_req = Split(ls_Req, SEP)
       
    lv_Selection = Split(Mid(ms_ListSelection, 3), SEP)

    If ms_ListToLink = SEP Then
        lv_ToLink = ""
    Else
        ls_HolderLink = UCase(grd_LinkList(ll_IndexFrame).Columns(0).Name)
        lv_ToLink = Split(Mid(ms_ListToLink, 3), SEP)
    End If
        
    
    Dim ll_Count1 As Long
    Dim ll_Count2 As Long
    Dim ll_NbSelection As Long
    Dim ll_NbToLink As Long
    
    ll_NbSelection = UBound(lv_Selection) - 1
    
    For ll_Count1 = 0 To ll_NbSelection
        Call BeginTran("Apply_ADD")
        lb_TranOpened = True
        
        ls_Req = Replace(lv_req(0), "$" & ls_HolderSel & "$", lv_Selection(ll_Count1), , , vbTextCompare)
        
        ExecuteSQLSafe mo_Db, ls_Req
        
        If mo_Db.SQLRowsAffected <= 0 Then
            RollbackTran ("Apply_ADD")
            lb_TranOpened = False
            ms_Errors = ms_Errors & lv_Selection(ll_Count1) & SEP
            GoTo NextItem
        End If
        
        If IsArray(lv_ToLink) Then
            ll_NbToLink = UBound(lv_ToLink) - 1
            
            For ll_Count2 = 0 To ll_NbToLink
                ls_Req = Replace(lv_req(1), "$" & ls_HolderSel & "$", lv_Selection(ll_Count1), , , vbTextCompare)
                ls_Req = Replace(ls_Req, "$" & ls_HolderLink & "$", lv_ToLink(ll_Count2), , , vbTextCompare)
                ExecuteSQLSafe mo_Db, ls_Req
                
                If mo_Db.SQLRowsAffected <= 0 Then
                    RollbackTran ("Apply_ADD")
                    lb_TranOpened = False
                    ms_Errors = ms_Errors & lv_Selection(ll_Count1) & SEP
                    GoTo NextItem
                End If
                
            Next ll_Count2
        End If

            
        Call CommitTran("Apply_ADD")
        lb_TranOpened = False
NextItem:
    Next ll_Count1
    
    Exit Sub
errHandler:
    If lb_TranOpened Then
        Call RollbackTran("Apply_ADD")
    End If
    Call ErrorHandler("ApplyChangesDB_ADD")
    
End Sub



Private Sub ApplyChangesDEL_User(ByVal al_ClassIndex As Long)
On Error GoTo errHandler
    Dim ll_IndexFrame As Long
    
    ll_IndexFrame = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IndexFrame
    

    If ms_ListSelection = SEP Then
        MsgBox "You must selection something in the grid " & grd_Temp(ll_IndexFrame).Title, vbInformation
        Exit Sub
    End If
    
    Call ApplyChangesDB_DEL_User(al_ClassIndex)

    Call ExitToMain(True)
    Exit Sub
    
errHandler:
    Call ErrorHandler("ApplyChangesDEL_User")
    
End Sub


Private Sub RefreshScreen(ByVal al_ClassIndex As Long)
On Error GoTo errHandler
    Dim ll_IndexFrame As Integer
    Dim ll_Count As Long
    Dim ll_NbGrid As Long
    Dim ll_Count1 As Long
    Dim lv_tag As Variant
    Dim lv_ToUnLink As Variant
    Dim lv_ToLink As Variant
    Dim ll_Key As Long
    Dim ls_Request As String
    Dim lv_Selection As Variant
    
    ll_IndexFrame = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IndexFrame
    
    ll_NbGrid = UBound(mt_ClassInfoLst(al_ClassIndex).ConfigDetail.ConfigGrid)
        
    For ll_Count = 0 To ll_NbGrid
        If mt_ClassInfoLst(al_ClassIndex).ConfigDetail.ConfigGrid(ll_Count).UnBound = False Then
            If mt_ClassInfoLst(al_ClassIndex).ConfigDetail.ConfigGrid(ll_Count).Grid.Requests(0) Like "*[$]*" Then
                lv_tag = Split(mt_ClassInfoLst(al_ClassIndex).ConfigDetail.ConfigGrid(ll_Count).Tag, SEP)
                Select Case lv_tag(1)
                    Case "grd_Temp"
                        ls_Request = grd_Temp(ll_IndexFrame).Requests(0)
                        grd_Temp(ll_IndexFrame).Requests = Replace(ls_Request, "$KEY$", grd_List(tbs_tab.SelectedItem.Tag).SelectedLine(0, 0))
                        If grd_Temp(ll_IndexFrame).Execute = False Then
                            Debug.Print "RefreshScreen grd_Temp -> Execute request grid error"
                        End If
                        grd_Temp(ll_IndexFrame).Requests = ls_Request
                    
                    Case "grd_AvailList"
                        ls_Request = grd_AvailList(ll_IndexFrame).Requests(0)
                        grd_AvailList(ll_IndexFrame).Requests = Replace(ls_Request, "$KEY$", grd_List(tbs_tab.SelectedItem.Tag).SelectedLine(0, 0))
                        If grd_AvailList(ll_IndexFrame).Execute = False Then
                            Debug.Print "RefreshScreen grd_Temp -> Execute request grid error"
                        End If
                        grd_AvailList(ll_IndexFrame).Requests = ls_Request
                        
                    
                    Case "grd_LinkList"
                        If ll_IndexFrame <> 6 Then
                            ls_Request = grd_LinkList(ll_IndexFrame).Requests(0)
                            grd_LinkList(ll_IndexFrame).Requests = Replace(ls_Request, "$KEY$", grd_List(tbs_tab.SelectedItem.Tag).SelectedLine(0, 0))
                            If grd_LinkList(ll_IndexFrame).Execute = False Then
                                Debug.Print "RefreshScreen grd_LinkList -> Execute request grid error"
                            End If
                            grd_LinkList(ll_IndexFrame).Requests = ls_Request
                            
                            If ms_ListToLink <> SEP Then
                                
                                lv_ToLink = Split(ms_ListToLink, SEP)
                                ms_ListToLink = SEP
                                For ll_Count1 = 0 To UBound(lv_ToLink)
                                    If grd_AvailList(ll_IndexFrame).SearchKey(True, lv_ToLink(ll_Count1)) Then
                                        Call btn_AddSel_Click(ll_IndexFrame)
                                    End If
                                Next ll_Count1
                            End If
                            
                            If ms_ListToUnLink <> SEP Then
                                lv_ToUnLink = Split(ms_ListToUnLink, SEP)
                                ms_ListToUnLink = SEP
                                For ll_Count1 = 0 To UBound(lv_ToUnLink)
                                    If grd_LinkList(ll_IndexFrame).SearchKey(True, lv_ToUnLink(ll_Count1)) Then
                                        Call btn_DelSel_Click(ll_IndexFrame)
                                    End If
                                Next ll_Count1
                            End If
                            
                            grd_LinkList(ll_IndexFrame).FirstLine
                            grd_LinkList(ll_IndexFrame).DeselectRow
                            
                            grd_AvailList(ll_IndexFrame).FirstLine
                            grd_AvailList(ll_IndexFrame).DeselectRow
                        Else
                            grd_LinkList(ll_IndexFrame).ClearGrid
                        End If
                    
                    Case "grd_Linked"
                        If grd_List(tbs_tab.SelectedItem.Tag).SelectedCount <> 0 Then
                            ls_Request = grd_Linked(ll_IndexFrame).Requests(0)
                            grd_Linked(ll_IndexFrame).Requests = Replace(ls_Request, "$KEY$", grd_List(tbs_tab.SelectedItem.Tag).SelectedLine(0, 0))
                            If grd_Linked(ll_IndexFrame).Execute = False Then
                                Debug.Print "RefreshScreen grd_Linked -> Execute request grid error"
                            End If
                            grd_Linked(ll_IndexFrame).Requests = ls_Request
                        Else
                            grd_Linked(ll_IndexFrame).ClearGrid
                        End If
                End Select
            Else
                lv_tag = Split(mt_ClassInfoLst(al_ClassIndex).ConfigDetail.ConfigGrid(ll_Count).Tag, SEP)
                Select Case lv_tag(1)
                    Case "grd_List"
                        ll_Key = -1
                        If grd_List(ll_IndexFrame).SelectedCount <> 0 Then
                            ll_Key = grd_List(ll_IndexFrame).SelectedLine(0, 0)
                        End If
                        
                       grd_List(ll_IndexFrame).Refresh
                        
                        If ll_Key <> -1 Then
                            If Not grd_List(ll_IndexFrame).SearchKey(True, ll_Key) Then
                                grd_List(ll_IndexFrame).FirstLine
                                grd_List(ll_IndexFrame).DeselectRow
                            End If
                        End If
                        
                    Case "grd_Selection"
                        grd_Selection(ll_IndexFrame).Refresh
                        
                        If ll_IndexFrame = 5 Or ll_IndexFrame = 8 Then
                            If grd_Selection(ll_IndexFrame).SearchKey(True, grd_List(tbs_tab.SelectedItem.Tag).SelectedLine(0, 0)) Then
                                grd_Selection(ll_IndexFrame).DeleteLine
                                grd_Selection(ll_IndexFrame).FirstLine
                                grd_Selection(ll_IndexFrame).DeselectRow
                            End If
                        End If
                        
                        
                        If ms_ListSelection <> SEP Then
                            lv_Selection = Split(ms_ListSelection, SEP)
                            For ll_Count1 = 0 To UBound(lv_Selection)
                                If grd_Selection(ll_IndexFrame).SearchKey(True, lv_Selection(ll_Count1)) Then
                                        grd_Selection(ll_IndexFrame).DeleteLine
                                End If
                            Next ll_Count1
                            grd_Selection(ll_IndexFrame).FirstLine
                            grd_Selection(ll_IndexFrame).DeselectRow
                         End If
                    
                    Case "grd_AvailList"
                        grd_AvailList(ll_IndexFrame).Refresh
                        
                        If ms_ListToLink <> SEP And ll_IndexFrame <> 6 Then
                            lv_ToLink = Split(ms_ListToLink, SEP)
                            For ll_Count1 = 0 To UBound(lv_ToLink)
                                If grd_AvailList(ll_IndexFrame).SearchKey(True, lv_ToLink(ll_Count1)) Then
                                    grd_AvailList(ll_IndexFrame).DeleteLine
                                End If
                            Next ll_Count1
                            grd_LinkList(ll_IndexFrame).FirstLine
                            grd_LinkList(ll_IndexFrame).DeselectRow
                            
                            grd_AvailList(ll_IndexFrame).FirstLine
                            grd_AvailList(ll_IndexFrame).DeselectRow
                        End If
                End Select
                
            End If
            
        End If
    Next ll_Count
        
    Exit Sub
    
errHandler:

    Call ErrorHandler("RefreshScreen")
    
End Sub



Private Sub ExitToMain(ByVal lb_WithFullRefresh As Boolean)
On Error GoTo errHandler
    
    
    
    If ms_Errors <> SEP Then
        Call DisplayScreen(10, False)
        Call InitError
    Else
        ml_AcitveClassIndex = tbs_tab.SelectedItem.Tag
        Call DisplayScreen(ml_AcitveClassIndex, lb_WithFullRefresh)
        tbs_tab.Enabled = True
    End If
    
    Exit Sub
    
errHandler:

    Call ErrorHandler("ExitToMain")
End Sub
Private Sub InitError()

On Error GoTo errHandler
    
    Dim lo_Grid As ArmGrid
    Dim lo_Grid1 As ArmGrid
    Dim lv_errors As Variant
    Dim ll_IndexFrame As Long
    Dim ll_Count As Long
    Dim ll_nbcol
    
    ll_IndexFrame = mt_ClassInfoLst(ml_AcitveClassIndex).ConfigRecord.IndexFrame


    If tbs_tab.SelectedItem.Tag = 0 Then
        Set lo_Grid = grd_Temp(ll_IndexFrame)
    Else
        Set lo_Grid = grd_LinkList(ll_IndexFrame)
        Set lo_Grid1 = grd_AvailList(ll_IndexFrame)
    End If
    
    lv_errors = Split(Mid(ms_Errors, 3), SEP)
    
    grd_Error(9).ClearGrid
    
    For ll_Count = 0 To UBound(lv_errors)
        
        If lo_Grid.SearchKey(True, lv_errors(ll_Count)) Then
            Call AddLineToGrid(lo_Grid, grd_Error(9), "", "", False)
            If Not lo_Grid1 Is Nothing Then
                Call AddLineToGrid(lo_Grid1, grd_Error(9), "", "", False)
            End If
        End If
    
    Next ll_Count
    
    
    ml_AcitveClassIndex = 10
    ms_Errors = SEP

    Exit Sub
    
errHandler:

    Call ErrorHandler("InitError")


End Sub


Private Sub InitUPD_User(ByVal al_ClassIndex As Long)
On Error GoTo errHandler
    
    Dim ll_IndexFrame As Long
    Dim ls_Request As String
    
    
    ll_IndexFrame = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IndexFrame
    ms_ListSelection = SEP
    ms_ListToLink = SEP
    ms_ListToUnLink = SEP
    
    Call DisplayScreen(al_ClassIndex, True)
    
    ms_ListSelection = SEP & grd_List(tbs_tab.SelectedItem.Tag).SelectedLine(0, 0) & SEP
    
    ls_Request = grd_AvailList(ll_IndexFrame).Requests(0)
    grd_AvailList(ll_IndexFrame).Requests = Replace(ls_Request, "$KEY$", grd_List(tbs_tab.SelectedItem.Tag).SelectedLine(0, 0))
    If grd_AvailList(ll_IndexFrame).Execute = False Then
        Debug.Print " InitUPD -> Execute request grid error"
    End If
    grd_AvailList(ll_IndexFrame).Requests = ls_Request
        
    
    ls_Request = grd_Temp(ll_IndexFrame).Requests(0)
    grd_Temp(ll_IndexFrame).Requests = Replace(ls_Request, "$KEY$", grd_List(tbs_tab.SelectedItem.Tag).SelectedLine(0, 0))
    If grd_Temp(ll_IndexFrame).Execute = False Then
        Debug.Print " InitUPD -> Execute request grid error"
    End If
    grd_Temp(ll_IndexFrame).Requests = ls_Request
    
    grd_Temp(ll_IndexFrame).DeselectRow
    
    If grd_List(tbs_tab.SelectedItem.Tag).SelectedLine(0, "Strat_Country") = "X" Then
        chk_StratCountry(ll_IndexFrame).value = True
    Else
        grd_LinkList(ll_IndexFrame).ClearGrid
        ls_Request = grd_LinkList(ll_IndexFrame).Requests(0)
        grd_LinkList(ll_IndexFrame).Requests = Replace(ls_Request, "$KEY$", grd_List(tbs_tab.SelectedItem.Tag).SelectedKey(0)(0), , , vbTextCompare)
        
        If grd_LinkList(ll_IndexFrame).Execute = False Then
            Debug.Print " InitUPD -> Execute request grid error"
        End If
        grd_LinkList(ll_IndexFrame).Requests = ls_Request
    End If
    
    Exit Sub
    
errHandler:

    Call ErrorHandler("InitUPD_User")
End Sub

Private Sub InitUPD_Master(ByVal al_ClassIndex As Long)
On Error GoTo errHandler
    Dim ll_IndexFrame As Long
    Dim ls_Request As String
    

    
    
    ll_IndexFrame = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IndexFrame
    
    ms_ListSelection = SEP
    ms_ListToLink = SEP
    ms_ListToUnLink = SEP
    
    Call DisplayScreen(al_ClassIndex, True)
    
    Call AddLineToGrid(grd_List(tbs_tab.SelectedItem.Tag), grd_Temp(ll_IndexFrame), ms_ListSelection, "", False)
    
    grd_Temp(ll_IndexFrame).DeselectRow
    
    ls_Request = grd_AvailList(ll_IndexFrame).Requests(0)
    grd_AvailList(ll_IndexFrame).Requests = Replace(ls_Request, "$KEY$", grd_List(tbs_tab.SelectedItem.Tag).SelectedLine(0, 0))
    If grd_AvailList(ll_IndexFrame).Execute = False Then
        Debug.Print " InitUPD_Master -> Execute request grid error"
    End If
    grd_AvailList(ll_IndexFrame).Requests = ls_Request
    
    grd_LinkList(ll_IndexFrame).ClearGrid
    ls_Request = grd_LinkList(ll_IndexFrame).Requests(0)
    grd_LinkList(ll_IndexFrame).Requests = Replace(ls_Request, "$KEY$", grd_List(tbs_tab.SelectedItem.Tag).SelectedKey(0)(0), , , vbTextCompare)
    
    If grd_LinkList(ll_IndexFrame).Execute = False Then
        Debug.Print " InitUPD -> Execute request grid error"
    End If
    grd_LinkList(ll_IndexFrame).Requests = ls_Request
    
    Exit Sub
    
errHandler:

    Call ErrorHandler("InitUPD_Master")
End Sub

Private Sub CopyGrid(ByVal grd_source As ArmGrid, ByVal grd_destination As ArmGrid, ByRef ls_List As String)
On Error GoTo errHandler
    Dim ll_nbline As Integer
    Dim i As Integer
    
    grd_destination.ClearGrid
    
    grd_source.FirstLine
    
    ll_nbline = grd_source.Rows - 1
    For i = 0 To ll_nbline
        Call AddLineToGrid(grd_source, grd_destination, ls_List, "", False)
        grd_source.NextLine
    Next i
    grd_source.FirstLine
    grd_destination.FirstLine
    
    Exit Sub
    
errHandler:
    Call ErrorHandler("CopyGrid")
End Sub

Private Sub ApplyChangesDB_UPD_User(ByVal al_ClassIndex As Long)
On Error GoTo errHandler
    
    Dim lv_req As Variant
    Dim ls_Req As String

    Dim lv_Selection As Variant
    Dim lv_ToLink As Variant
    Dim lv_ToUnLink As Variant
    
    Dim ls_HolderSel As String
    Dim ls_HolderLink As String
    
    Dim lb_TranOpened As Boolean
    
    Dim ll_IndexFrame As Long
    
    ll_IndexFrame = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IndexFrame
       
    ls_Req = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.RequestToApply
    
    If InStr(1, ls_Req, "$STRAT_COUNTRY$", vbTextCompare) Then
        If chk_StratCountry(ll_IndexFrame).value = True Then
            ms_ListToLink = SEP
            ms_ListToUnLink = SEP
        End If
        ls_HolderLink = UCase(grd_LinkList(ll_IndexFrame).Columns(0).Name)
    End If
    
    If InStr(1, ls_Req, "$ICONCURRENCY$", vbTextCompare) Then
       ls_Req = Replace(ls_Req, "$ICONCURRENCY$", grd_Temp(ll_IndexFrame).Data(0, "iConcurrency"), , , vbTextCompare)
    End If
    
    ls_Req = ReplaceHolders(UserControl.Controls, fra_frames(ll_IndexFrame), ls_Req)
    lv_req = Split(ls_Req, SEP)
       
    lv_Selection = Split(Mid(ms_ListSelection, 3), SEP)
    ls_HolderSel = UCase(grd_Temp(ll_IndexFrame).Columns(0).Name)

    If ms_ListToLink = SEP Then
        lv_ToLink = ""
    Else
        ls_HolderLink = UCase(grd_LinkList(ll_IndexFrame).Columns(0).Name)
        lv_ToLink = Split(Mid(ms_ListToLink, 3), SEP)
    End If
    
    If ms_ListToUnLink = SEP Then
        lv_ToUnLink = ""
    Else
        ls_HolderLink = UCase(grd_LinkList(ll_IndexFrame).Columns(0).Name)
        lv_ToUnLink = Split(Mid(ms_ListToUnLink, 3), SEP)
    End If
    
    
    Dim ll_Count1 As Long
    Dim ll_Count2 As Long
    Dim ll_NbSelection As Long
    Dim ll_NbToLink As Long
    Dim ll_NbToUnLink As Long
    
    ll_NbSelection = UBound(lv_Selection) - 1
    
    For ll_Count1 = 0 To ll_NbSelection
        Call BeginTran("Apply_UPD_User")
        lb_TranOpened = True
        
        ls_Req = Replace(lv_req(0), "$" & ls_HolderSel & "$", lv_Selection(ll_Count1), , , vbTextCompare)
        
        ExecuteSQLSafe mo_Db, ls_Req
        
        If mo_Db.SQLRowsAffected <= 0 Then
            RollbackTran ("Apply_UPD_User")
            lb_TranOpened = False
            ms_Errors = ms_Errors & lv_Selection(ll_Count1) & SEP
            GoTo NextItem
        End If
        
        If IsArray(lv_ToLink) Then
            ll_NbToLink = UBound(lv_ToLink) - 1
            
            For ll_Count2 = 0 To ll_NbToLink
                ls_Req = Replace(lv_req(1), "$" & ls_HolderSel & "$", lv_Selection(ll_Count1), , , vbTextCompare)
                ls_Req = Replace(ls_Req, "$" & ls_HolderLink & "$", lv_ToLink(ll_Count2), , , vbTextCompare)
                ExecuteSQLSafe mo_Db, ls_Req
                
                If mo_Db.SQLRowsAffected <= 0 Then
                    RollbackTran ("Apply_UPD_User")
                    lb_TranOpened = False
                    ms_Errors = ms_Errors & lv_Selection(ll_Count1) & SEP
                    GoTo NextItem
                End If

            Next ll_Count2
        End If

        
        If IsArray(lv_ToUnLink) Then
            ll_NbToUnLink = UBound(lv_ToUnLink) - 1
            For ll_Count2 = 0 To ll_NbToUnLink
                ls_Req = Replace(lv_req(2), "$" & ls_HolderSel & "$", lv_Selection(ll_Count1), , , vbTextCompare)
                ls_Req = Replace(ls_Req, "$" & ls_HolderLink & "$", lv_ToUnLink(ll_Count2), , , vbTextCompare)
                ExecuteSQLSafe mo_Db, ls_Req
                
                If mo_Db.SQLRowsAffected <= 0 Then
                    RollbackTran ("Apply_UPD_User")
                    lb_TranOpened = False
                    ms_Errors = ms_Errors & lv_Selection(ll_Count1) & SEP
                    GoTo NextItem
                End If
                
            Next ll_Count2
        End If
        
        
        If Not IsArray(lv_ToLink) And Not IsArray(lv_ToUnLink) Then
                ls_Req = Replace(lv_req(2), "$" & ls_HolderSel & "$", lv_Selection(ll_Count1), , , vbTextCompare)
                ls_Req = Replace(ls_Req, "$" & ls_HolderLink & "$", "NULL", , , vbTextCompare)
                ExecuteSQLSafe mo_Db, ls_Req
                
                If mo_Db.SQLRowsAffected <= 0 Then
                    RollbackTran ("Apply_UPD_User")
                    lb_TranOpened = False
                    ms_Errors = ms_Errors & lv_Selection(ll_Count1) & SEP
                    GoTo NextItem
                End If
        End If
        
        Call CommitTran("Apply_UPD_User")
        lb_TranOpened = False
NextItem:
    
    Next ll_Count1
    
    Exit Sub
errHandler:
    If lb_TranOpened Then
        Call RollbackTran("Apply_UPD_User")
    End If
    Call ErrorHandler("ApplyChangesDB_UPD_User")
    
End Sub
Private Sub ReinitSAME(ByVal al_ClassIndex As Long)
    
On Error GoTo errHandler
    
    Dim ll_IndexFrame As Long
    
    ll_IndexFrame = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IndexFrame
    
    grd_Selection(ll_IndexFrame).Refresh
    grd_Temp(ll_IndexFrame).ClearGrid
    If grd_Selection(ll_IndexFrame).SearchKey(True, grd_List(tbs_tab.SelectedItem.Tag).SelectedLine(0, 0)) Then
        grd_Selection(ll_IndexFrame).DeleteLine
        grd_Selection(ll_IndexFrame).FirstLine
        grd_Selection(ll_IndexFrame).DeselectRow
    End If
    
    ms_ListSelection = SEP
    
    Exit Sub
    
errHandler:
    Call ErrorHandler("ReinitSAME")

End Sub


Private Sub ApplyChangesDB_UPD_Master(ByVal al_ClassIndex As Long)
On Error GoTo errHandler
    
    Dim lv_req As Variant
    Dim ls_Req As String

    Dim lv_Selection As Variant
    Dim lv_ToLink As Variant
    Dim lv_ToUnLink As Variant
    
    Dim ls_HolderSel As String
    Dim ls_HolderLink As String
    
    Dim lb_TranOpened As Boolean
    
    Dim ll_IndexFrame As Long
    
    
    ll_IndexFrame = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IndexFrame
       
    ls_Req = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.RequestToApply
           
    ls_Req = ReplaceHolders(UserControl.Controls, fra_frames(ll_IndexFrame), ls_Req)
    lv_req = Split(ls_Req, SEP)
       
    lv_Selection = Split(Mid(ms_ListSelection, 3), SEP)
    ls_HolderSel = UCase(grd_Temp(ll_IndexFrame).Columns(0).Name)

    If ms_ListToLink = SEP Then
        lv_ToLink = ""
    Else
        ls_HolderLink = UCase(grd_LinkList(ll_IndexFrame).Columns(0).Name)
        lv_ToLink = Split(Mid(ms_ListToLink, 3), SEP)
    End If
    
    If ms_ListToUnLink = SEP Then
        lv_ToUnLink = ""
    Else
        ls_HolderLink = UCase(grd_LinkList(ll_IndexFrame).Columns(0).Name)
        lv_ToUnLink = Split(Mid(ms_ListToUnLink, 3), SEP)
    End If
    
    
    Dim ll_Count2 As Long
    Dim ll_NbToLink As Long
    Dim ll_NbToUnLink As Long
    
      
        
    If IsArray(lv_ToLink) Then
        ll_NbToLink = UBound(lv_ToLink) - 1
        For ll_Count2 = 0 To ll_NbToLink
            Call BeginTran("Apply_UPD_Master")
            lb_TranOpened = True
            
            ls_Req = Replace(lv_req(0), "$" & ls_HolderLink & "$", lv_ToLink(ll_Count2), , , vbTextCompare)
            If Not grd_LinkList(ll_IndexFrame).SearchKey(True, lv_ToLink(ll_Count2)) Then
                Call RollbackTran("Apply_UPD_Master")
                lb_TranOpened = False
                ms_Errors = ms_Errors & lv_ToLink(ll_Count2) & SEP
                GoTo NextItemToLink
            End If
            ls_Req = Replace(ls_Req, "$ICONCURRENCY$", grd_LinkList(ll_IndexFrame).SelectedLine(0, "iConcurrency"), , , vbTextCompare)
            ExecuteSQLSafe mo_Db, ls_Req
            
            If mo_Db.SQLRowsAffected <= 0 Then
                RollbackTran ("Apply_UPD_Master")
                lb_TranOpened = False
                ms_Errors = ms_Errors & lv_ToLink(ll_Count2) & SEP
                GoTo NextItemToLink
            End If
            
            ls_Req = Replace(lv_req(1), "$" & ls_HolderSel & "$", lv_Selection(0), , , vbTextCompare)
            ls_Req = Replace(ls_Req, "$" & ls_HolderLink & "$", lv_ToLink(ll_Count2), , , vbTextCompare)
            ExecuteSQLSafe mo_Db, ls_Req
            
            If mo_Db.SQLRowsAffected <= 0 Then
                RollbackTran ("Apply_UPD_Master")
                lb_TranOpened = False
                ms_Errors = ms_Errors & lv_ToLink(ll_Count2) & SEP
                GoTo NextItemToLink
            End If
            
            Call CommitTran("Apply_UPD_Master")
            lb_TranOpened = False
NextItemToLink:
        Next ll_Count2
    End If

        
    If IsArray(lv_ToUnLink) Then
        ll_NbToUnLink = UBound(lv_ToUnLink) - 1
        For ll_Count2 = 0 To ll_NbToUnLink
            Call BeginTran("Apply_UPD_Master")
            lb_TranOpened = True
            
            ls_Req = Replace(lv_req(0), "$" & ls_HolderLink & "$", lv_ToUnLink(ll_Count2), , , vbTextCompare)
            
            If Not grd_AvailList(ll_IndexFrame).SearchKey(True, lv_ToUnLink(ll_Count2)) Then
                Call RollbackTran("Apply_UPD_Master")
                lb_TranOpened = False
                ms_Errors = ms_Errors & lv_ToUnLink(ll_Count2) & SEP
                GoTo NextItemToUnLink
            End If
            
            ls_Req = Replace(ls_Req, "$ICONCURRENCY$", grd_AvailList(ll_IndexFrame).SelectedLine(0, "iConcurrency"), , , vbTextCompare)
            ExecuteSQLSafe mo_Db, ls_Req
                          
            If mo_Db.SQLRowsAffected <= 0 Then
                RollbackTran ("Apply_UPD_Master")
                lb_TranOpened = False
                ms_Errors = ms_Errors & lv_ToUnLink(ll_Count2) & SEP
                GoTo NextItemToUnLink
            End If
              
                          
                          
            ls_Req = Replace(lv_req(2), "$" & ls_HolderSel & "$", lv_Selection(0), , , vbTextCompare)
            ls_Req = Replace(ls_Req, "$" & ls_HolderLink & "$", lv_ToUnLink(ll_Count2), , , vbTextCompare)
            ExecuteSQLSafe mo_Db, ls_Req
            
            If mo_Db.SQLRowsAffected <= 0 Then
                RollbackTran ("Apply_UPD_Master")
                lb_TranOpened = False
                ms_Errors = ms_Errors & lv_ToUnLink(ll_Count2) & SEP
                GoTo NextItemToUnLink
            End If
            
            Call CommitTran("Apply_UPD_Master")
            lb_TranOpened = False
NextItemToUnLink:
        Next ll_Count2
    End If
    
    
    Exit Sub
errHandler:
    If lb_TranOpened Then
        Call RollbackTran("Apply_UPD_Master")
    End If
    Call ErrorHandler("ApplyChangesDB_UPD_Master")
End Sub
    

Private Sub ApplyChangesDB_SAME_User(ByVal al_ClassIndex As Long)
On Error GoTo errHandler
    
    Dim lv_req As Variant
    Dim ls_Req As String

    Dim lv_Selection As Variant
    Dim lv_ToLink As Variant
    
    Dim ls_HolderSel As String
    Dim ls_HolderLink As String
    
    Dim lb_TranOpened As Boolean
    
    Dim ll_IndexFrame As Long
    
    ll_IndexFrame = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IndexFrame
       
    ls_Req = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.RequestToApply
       
    
    ls_Req = ReplaceHolders(UserControl.Controls, fra_frames(ll_IndexFrame), ls_Req)
    lv_req = Split(ls_Req, SEP)
       
    lv_Selection = Split(Mid(ms_ListSelection, 3), SEP)
    ls_HolderSel = UCase(grd_Temp(ll_IndexFrame).Columns(0).Name)

    If ms_ListToLink = SEP Then
        lv_ToLink = ""
    Else
        ls_HolderLink = UCase(grd_LinkList(ll_IndexFrame).Columns(0).Name)
        lv_ToLink = Split(Mid(ms_ListToLink, 3), SEP)
    End If
        
    
    Dim ll_Count1 As Long
    Dim ll_Count2 As Long
    Dim ll_NbSelection As Long
    Dim ll_NbToLink As Long
    Dim ll_NbToUnLink As Long
    ll_NbSelection = UBound(lv_Selection) - 1
    
    For ll_Count1 = 0 To ll_NbSelection
        Call BeginTran("Apply_SAME_User")
        lb_TranOpened = True
        
        ls_Req = Replace(lv_req(0), "$ICONCURRENCY$", grd_Temp(ll_IndexFrame).Data(ll_Count1, "iConcurrency"), , , vbTextCompare)
        ls_Req = Replace(ls_Req, "$STRAT_COUNTRY$", "", , , vbTextCompare)
        ls_Req = Replace(ls_Req, "$" & ls_HolderSel & "$", grd_Temp(ll_IndexFrame).Data(ll_Count1, ls_HolderSel), , , vbTextCompare)
        
        ExecuteSQLSafe mo_Db, ls_Req
        
        ls_Req = Replace(lv_req(1), "$" & ls_HolderSel & "$", grd_Temp(ll_IndexFrame).Data(ll_Count1, ls_HolderSel), , , vbTextCompare)
        
        ExecuteSQLSafe mo_Db, ls_Req
        
        If IsArray(lv_ToLink) Then
            ll_NbToLink = UBound(lv_ToLink) - 1
            
            For ll_Count2 = 0 To ll_NbToLink
                ls_Req = Replace(lv_req(2), "$" & ls_HolderSel & "$", grd_Temp(ll_IndexFrame).Data(ll_Count1, ls_HolderSel), , , vbTextCompare)
                ls_Req = Replace(ls_Req, "$" & ls_HolderLink & "$", lv_ToLink(ll_Count2), , , vbTextCompare)
                ExecuteSQLSafe mo_Db, ls_Req
            Next ll_Count2
        End If

        Call CommitTran("Apply_SAME_User")
        lb_TranOpened = False
    
    Next ll_Count1
    
    Exit Sub
errHandler:
    If lb_TranOpened Then
        Call RollbackTran("Apply_SAME_User")
    End If
    Call ErrorHandler("ApplyChangesDB_SAME_User")
    
End Sub

Private Sub ApplyChangesDB_SAME_Master(ByVal al_ClassIndex As Long)
On Error GoTo errHandler
    
    Dim lv_req As Variant
    Dim ls_Req As String

    Dim lv_Selection As Variant
    Dim lv_ToLink As Variant
    
    Dim ls_HolderSel As String
    Dim ls_HolderLink As String
    
    Dim lb_TranOpened As Boolean
    
    Dim ll_IndexFrame As Long
    
    ll_IndexFrame = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IndexFrame
       
    ls_Req = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.RequestToApply
       
    
    ls_Req = ReplaceHolders(UserControl.Controls, fra_frames(ll_IndexFrame), ls_Req)
    lv_req = Split(ls_Req, SEP)
       
    lv_Selection = Split(Mid(ms_ListSelection, 3), SEP)
    ls_HolderSel = UCase(grd_Temp(ll_IndexFrame).Columns(0).Name)

    If ms_ListToLink = SEP Then
        lv_ToLink = ""
    Else
        ls_HolderLink = UCase(grd_LinkList(ll_IndexFrame).Columns(0).Name)
        lv_ToLink = Split(Mid(ms_ListToLink, 3), SEP)
    End If
        
    
    Dim ll_Count1 As Long
    Dim ll_Count2 As Long
    Dim ll_NbSelection As Long
    Dim ll_NbToLink As Long
    Dim ll_NbToUnLink As Long
    ll_NbSelection = UBound(lv_Selection) - 1
    
    For ll_Count1 = 0 To ll_NbSelection
        Call BeginTran("Apply_SAME_Master")
        lb_TranOpened = True
        ls_Req = Replace(lv_req(0), "$" & ls_HolderSel & "$", grd_Temp(ll_IndexFrame).Data(ll_Count1, ls_HolderSel), , , vbTextCompare)
        
        ExecuteSQLSafe mo_Db, ls_Req
        
        If IsArray(lv_ToLink) Then
            ll_NbToLink = UBound(lv_ToLink) - 1
            
            For ll_Count2 = 0 To ll_NbToLink
            
                ls_Req = Replace(lv_req(1), "$" & ls_HolderSel & "$", grd_Temp(ll_IndexFrame).Data(ll_Count1, ls_HolderSel), , , vbTextCompare)
                ls_Req = Replace(ls_Req, "$ICONCURRENCY$", grd_LinkList(ll_IndexFrame).Data(ll_Count2, "iConcurrency"), , , vbTextCompare)
                ls_Req = Replace(ls_Req, "$" & ls_HolderLink & "$", grd_LinkList(ll_IndexFrame).Data(0, 0), , , vbTextCompare)
                ExecuteSQLSafe mo_Db, ls_Req
                
                ls_Req = Replace(lv_req(2), "$" & ls_HolderSel & "$", grd_Temp(ll_IndexFrame).Data(ll_Count1, ls_HolderSel), , , vbTextCompare)
                ls_Req = Replace(ls_Req, "$" & ls_HolderLink & "$", lv_ToLink(ll_Count2), , , vbTextCompare)
                ExecuteSQLSafe mo_Db, ls_Req
                
            Next ll_Count2
        End If

        Call CommitTran("Apply_SAME_Master")
        lb_TranOpened = False
    
    Next ll_Count1
    
    Exit Sub
errHandler:
    If lb_TranOpened Then
        Call RollbackTran("Apply_SAME_Master")
    End If
    Call ErrorHandler("ApplyChangesDB_SAME_Master")
    
End Sub


Private Sub ApplyChangesDB_DEL_User(ByVal al_ClassIndex As Long)
On Error GoTo errHandler
    
    Dim lv_req As Variant
    Dim ls_Req As String

    Dim lv_Selection As Variant
    
    Dim ls_HolderSel As String
    Dim ls_HolderLink As String
    
    Dim lb_TranOpened As Boolean
    
    Dim ll_IndexFrame As Long
    
    ll_IndexFrame = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.IndexFrame
       
    ls_Req = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.RequestToApply
    
    ls_Req = ReplaceHolders(UserControl.Controls, fra_frames(ll_IndexFrame), ls_Req)
    lv_req = Split(ls_Req, SEP)
       
    lv_Selection = Split(Mid(ms_ListSelection, 3), SEP)
    ls_HolderSel = UCase(grd_Temp(ll_IndexFrame).Columns(0).Name)
   
    
    Dim ll_Count1 As Long
    Dim ll_NbSelection As Long
    ll_NbSelection = UBound(lv_Selection) - 1
    
    For ll_Count1 = 0 To ll_NbSelection
        Call BeginTran("Apply_DEL_User")
        lb_TranOpened = True
        
        ls_Req = Replace(lv_req(0), "$" & ls_HolderSel & "$", lv_Selection(ll_Count1), , , vbTextCompare)
        ExecuteSQLSafe mo_Db, ls_Req
        
        ls_Req = Replace(lv_req(1), "$" & ls_HolderSel & "$", lv_Selection(ll_Count1), , , vbTextCompare)
        ExecuteSQLSafe mo_Db, ls_Req
        
        If mo_Db.SQLRowsAffected <= 0 Then
            RollbackTran ("Apply_DEL_User")
            lb_TranOpened = False
            ms_Errors = ms_Errors & lv_Selection(ll_Count1) & SEP
            GoTo NextItem
        End If
    
        Call CommitTran("Apply_DEL_User")
        lb_TranOpened = False
        
NextItem:
    Next ll_Count1
    
    Exit Sub
errHandler:
    If lb_TranOpened Then
        Call RollbackTran("Apply_DEL_User")
    End If
    Call ErrorHandler("ApplyChangesDB_DEL_User")
    
End Sub

Private Sub ApplyChangesDB_DEL_Master(ByVal al_ClassIndex As Long)
On Error GoTo errHandler
    
    Dim ls_Req As String
       
    ls_Req = mt_ClassInfoLst(al_ClassIndex).ConfigRecord.RequestToApply
                 
    ls_Req = Replace(ls_Req, "$MKT_Key$", grd_List(tbs_tab.SelectedItem.Tag).SelectedLine(0, 0), , , vbTextCompare)
    ExecuteSQLSafe mo_Db, ls_Req
    
    If mo_Db.SQLRowsAffected <= 0 Then
        MsgBox "Enable to delete the users for the selected master.", vbCritical + vbOKOnly
    End If
    
    Exit Sub

errHandler:
    Call ErrorHandler("ApplyChangesDB_DEL_Master")
    
End Sub

Private Function BeginTran(as_Tran As String) As Boolean

On Error GoTo errHandler
    BeginTran = False
    ExecuteSQLSafe mo_Db, "BEGIN TRANSACTION " & as_Tran

    BeginTran = True
    Exit Function
    
errHandler:
    mo_Db.Disconnect
    Set mo_Db = Nothing
    MsgBox "A Fatal error occured in " & SCREEN_NAME & ".BeginTran, your application will be close. Please contact your IT support"
    End
End Function

Private Function CommitTran(as_Tran As String) As Boolean

On Error GoTo errHandler
    CommitTran = False
    ExecuteSQLSafe mo_Db, "COMMIT TRANSACTION " & as_Tran

    CommitTran = True
    Exit Function
    
errHandler:
    mo_Db.Disconnect
    Set mo_Db = Nothing
    MsgBox "A Fatal error occured in " & SCREEN_NAME & ".CommitTran, your application will be close. Please contact your IT support"
    End

End Function

Private Function RollbackTran(as_Tran As String) As Boolean
    
    Dim ll_errNumber As Long, ls_ErrSrc As String, ls_ErrDesc As String
    ll_errNumber = Err.Number
    ls_ErrSrc = Err.Source
    ls_ErrDesc = Err.Description

On Error GoTo errHandler
    RollbackTran = False
    
    ExecuteSQLSafe mo_Db, "ROLLBACK TRANSACTION " & as_Tran


    Err.Number = ll_errNumber
    Err.Source = ls_ErrSrc
    Err.Description = ls_ErrDesc

    RollbackTran = True
    Exit Function
    
errHandler:
    mo_Db.Disconnect
    Set mo_Db = Nothing
    MsgBox "A Fatal error occured in " & SCREEN_NAME & ".RollbackTran, your application will be close. Please contact your IT support"
    End
End Function



Private Sub tlb_main_action(ByVal as_Role As String, as_Language As String)
On Error GoTo errHandler
    Dim ll_ClassIndex As Long
    
    
    ll_ClassIndex = ml_AcitveClassIndex
    
    Dim ll_IndexFrame As Long
    ll_IndexFrame = mt_ClassInfoLst(ll_ClassIndex).ConfigRecord.IndexFrame
    
    Call LockScreen(True)
    
    tbs_tab.Enabled = False
       
    Select Case as_Role
        Case "A" 'Add User
            ml_AcitveClassIndex = 2
            ll_ClassIndex = ml_AcitveClassIndex
            Call DisplayScreen(ll_ClassIndex, True)
        
        Case "B" 'update
            If grd_List(tbs_tab.SelectedItem.Tag).SelectedCount <> 0 Then
                ml_AcitveClassIndex = 4
                ll_ClassIndex = ml_AcitveClassIndex
                Call InitUPD_User(ll_ClassIndex)
            Else
                tbs_tab.Enabled = True
            End If
        
        Case "C" 'Delete User
            ml_AcitveClassIndex = 3
            ll_ClassIndex = ml_AcitveClassIndex
            Call DisplayScreen(ll_ClassIndex, True)
        
        Case "D" 'Delete Master
            ml_AcitveClassIndex = 9
            ll_ClassIndex = ml_AcitveClassIndex
            Call ApplyChangesDEL_Master(ll_ClassIndex)
            tbs_tab.Enabled = True
            
        Case "E" 'update Master
            If grd_List(tbs_tab.SelectedItem.Tag).SelectedCount <> 0 Then
                ml_AcitveClassIndex = 7
                ll_ClassIndex = ml_AcitveClassIndex
                Call InitUPD_Master(ll_ClassIndex)
            Else
                tbs_tab.Enabled = True
            End If
            
        Case "F" 'Refresf
            Call RefreshScreen(ll_ClassIndex)
            If ml_AcitveClassIndex <= 1 Then tbs_tab.Enabled = True

        Case "H" 'Validate ADD
            Call ApplyChangesADD(ll_ClassIndex)
        
        Case "I" 'reinit
            Call DisplayScreen(ll_ClassIndex, True)
            
        Case "J" 'reinit upd
            Call InitUPD_User(ll_ClassIndex)
        
        Case "K" 'reinit upd
            Call ApplyChangesUPD_Master(ll_ClassIndex)
            
        Case "L"
            Call InitUPD_Master(ll_ClassIndex)
            
        Case "M"
            Call ApplyChangesDEL_User(ll_ClassIndex)
        
        Case "N" 'validate apply Same
            Call ApplyChangesSAME_User(ll_ClassIndex)
            
        Case "Q" 'Validate apply same master
            Call ApplyChangesSAME_Master(ll_ClassIndex)
        
        Case "U" 'Validate UPD User
            Call ApplyChangesUPD_User(ll_ClassIndex)
            
        Case "O" 'reinit SAME screen
            Call ReinitSAME(ll_ClassIndex)
            
        Case "T" 'Exit Main
            tbs_tab.Enabled = True
            RaiseEvent quit
        
        Case "S" 'Exit Screen
            If ml_AcitveClassIndex = 10 Then
                Call ExitToMain(True)
            Else
                Call ExitToMain(False)
            End If
        Case "X" 'copy
            ml_AcitveClassIndex = 6
            ll_ClassIndex = ml_AcitveClassIndex
            Call DisplayScreen(ll_ClassIndex, True)
            
        Case "V"
            Call ApplyChangesCPY(ll_ClassIndex)
            
        Case "Y" 'Tranfer down
            Call AddLineToGrid(grd_Selection(ll_IndexFrame), grd_Temp(ll_IndexFrame), ms_ListSelection, "", True)
    
        Case "Z" 'Transfer up
            Call AddLineToGrid(grd_Temp(ll_IndexFrame), grd_Selection(ll_IndexFrame), ms_ListSelection, "", True)
        
        
    End Select
    
    Call LockScreen(False)
    
    Exit Sub
    
errHandler:
    Call LockScreen(False)
    Call ErrorHandler("tlb_main_action")
End Sub

