VERSION 5.00
Begin VB.UserControl SOM_ExcelExp 
   ClientHeight    =   10005
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   15090
   LockControls    =   -1  'True
   ScaleHeight     =   10005
   ScaleWidth      =   15090
   Begin VB.CheckBox chk_field 
      Caption         =   "#Total value currency"
      Height          =   225
      Index           =   242
      Left            =   11370
      TabIndex        =   80
      Tag             =   "P"
      Top             =   4410
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Quote offer date"
      Height          =   225
      Index           =   241
      Left            =   11370
      TabIndex        =   79
      Tag             =   "P"
      Top             =   4140
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Quote include"
      Height          =   225
      Index           =   203
      Left            =   7590
      TabIndex        =   78
      Tag             =   "C"
      Top             =   1980
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Quote freight cost CHF"
      Height          =   225
      Index           =   232
      Left            =   11370
      TabIndex        =   77
      Top             =   1710
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Project size in"
      Height          =   225
      Index           =   10
      Left            =   60
      TabIndex        =   76
      Top             =   3870
      Width           =   3675
   End
   Begin VB.CheckBox chk_SelectedRowsOnly 
      Caption         =   "#Only selected rows"
      Height          =   255
      Left            =   810
      TabIndex        =   75
      Tag             =   "SelectedRowsOnly"
      Top             =   780
      Width           =   2925
   End
   Begin Project1.Saved_Select SOM_Selection 
      Height          =   2235
      Left            =   150
      TabIndex        =   74
      Top             =   6675
      Width           =   4770
      _ExtentX        =   8414
      _ExtentY        =   3942
   End
   Begin VB.CommandButton btn_selectAll 
      Caption         =   "#Check all"
      Height          =   315
      Left            =   4260
      TabIndex        =   73
      Tag             =   "btn_SelectAll"
      Top             =   750
      Width           =   1875
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Project name"
      Height          =   225
      Index           =   1
      Left            =   60
      TabIndex        =   72
      Top             =   1440
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Won Lost Duplicate date"
      Height          =   225
      Index           =   240
      Left            =   11370
      TabIndex        =   71
      Tag             =   "C"
      Top             =   3870
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Won Lost Duplicate flag"
      Height          =   225
      Index           =   239
      Left            =   11370
      TabIndex        =   70
      Tag             =   "P"
      Top             =   3600
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Quote last upd user"
      Height          =   225
      Index           =   238
      Left            =   11370
      TabIndex        =   69
      Tag             =   "P"
      Top             =   3330
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Quote last updated"
      Height          =   225
      Index           =   237
      Left            =   11370
      TabIndex        =   68
      Tag             =   "P"
      Top             =   3060
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Quote entered by"
      Height          =   225
      Index           =   236
      Left            =   11370
      TabIndex        =   67
      Tag             =   "P"
      Top             =   2790
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Quote date entered"
      Height          =   225
      Index           =   235
      Left            =   11370
      TabIndex        =   66
      Tag             =   "P"
      Top             =   2520
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Quote back office person"
      Height          =   225
      Index           =   234
      Left            =   11370
      TabIndex        =   65
      Tag             =   "Q"
      Top             =   2250
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Quote realisation %"
      Height          =   225
      Index           =   233
      Left            =   11370
      TabIndex        =   64
      Tag             =   "C"
      Top             =   1980
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Clg function"
      Height          =   225
      Index           =   19
      Left            =   60
      TabIndex        =   63
      Top             =   6300
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#I5 reference"
      Height          =   225
      Index           =   18
      Left            =   60
      TabIndex        =   62
      Top             =   6030
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Project last activity user"
      Height          =   225
      Index           =   17
      Left            =   60
      TabIndex        =   61
      Top             =   5760
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Project last activity"
      Height          =   225
      Index           =   16
      Left            =   60
      TabIndex        =   60
      Top             =   5490
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Project entered by"
      Height          =   225
      Index           =   15
      Left            =   60
      TabIndex        =   59
      Top             =   5220
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Project date entered"
      Height          =   225
      Index           =   14
      Left            =   60
      TabIndex        =   58
      Top             =   4950
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Duration of project"
      Height          =   225
      Index           =   13
      Left            =   60
      TabIndex        =   57
      Top             =   4680
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Expected order date"
      Height          =   225
      Index           =   12
      Left            =   60
      TabIndex        =   56
      Top             =   4410
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Follow up date"
      Height          =   225
      Index           =   11
      Left            =   60
      TabIndex        =   55
      Top             =   4140
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Project size"
      Height          =   225
      Index           =   9
      Left            =   60
      TabIndex        =   54
      Top             =   3600
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Project sales person"
      Height          =   225
      Index           =   8
      Left            =   60
      TabIndex        =   53
      Top             =   3330
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Market segment"
      Height          =   225
      Index           =   7
      Left            =   60
      TabIndex        =   52
      Top             =   3060
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Project status"
      Height          =   225
      Index           =   6
      Left            =   60
      TabIndex        =   51
      Top             =   2790
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Project country"
      Height          =   225
      Index           =   5
      Left            =   60
      TabIndex        =   50
      Top             =   2520
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Project zip"
      Height          =   225
      Index           =   4
      Left            =   60
      TabIndex        =   49
      Top             =   2250
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Project town"
      Height          =   225
      Index           =   3
      Left            =   60
      TabIndex        =   48
      Top             =   1980
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Project address"
      Height          =   225
      Index           =   2
      Left            =   60
      TabIndex        =   47
      Top             =   1710
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Project number"
      Height          =   225
      Index           =   0
      Left            =   60
      TabIndex        =   46
      Top             =   1170
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Quote freight cost in"
      Height          =   225
      Index           =   231
      Left            =   11370
      TabIndex        =   45
      Tag             =   "P"
      Top             =   1440
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Quote freight cost"
      Height          =   225
      Index           =   230
      Left            =   11370
      TabIndex        =   44
      Tag             =   "Q"
      Top             =   1170
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Quote valid until"
      Height          =   225
      Index           =   229
      Left            =   7590
      TabIndex        =   43
      Tag             =   "C"
      Top             =   9000
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Total prime margin"
      Height          =   225
      Index           =   228
      Left            =   7590
      TabIndex        =   42
      Tag             =   "P"
      Top             =   8730
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Total value CHF"
      Height          =   225
      Index           =   227
      Left            =   7590
      TabIndex        =   41
      Tag             =   "P"
      Top             =   8460
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Total DB%"
      Height          =   225
      Index           =   226
      Left            =   7590
      TabIndex        =   40
      Tag             =   "P"
      Top             =   8190
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#CUS prime margin"
      Height          =   225
      Index           =   225
      Left            =   7590
      TabIndex        =   39
      Tag             =   "P"
      Top             =   7920
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#CUS value CHF"
      Height          =   225
      Index           =   224
      Left            =   7590
      TabIndex        =   38
      Tag             =   "P"
      Top             =   7650
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#CUS DB%"
      Height          =   225
      Index           =   223
      Left            =   7590
      TabIndex        =   37
      Tag             =   "Q"
      Top             =   7380
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#CUS quote value"
      Height          =   225
      Index           =   222
      Left            =   7590
      TabIndex        =   36
      Tag             =   "C"
      Top             =   7110
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#CUS area in"
      Height          =   225
      Index           =   221
      Left            =   7590
      TabIndex        =   35
      Tag             =   "P"
      Top             =   6840
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#CUS area"
      Height          =   225
      Index           =   220
      Left            =   7590
      TabIndex        =   34
      Tag             =   "Q"
      Top             =   6570
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#CUS system"
      Height          =   225
      Index           =   219
      Left            =   7590
      TabIndex        =   33
      Tag             =   "C"
      Top             =   6300
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#SEMI prime margin"
      Height          =   225
      Index           =   218
      Left            =   7590
      TabIndex        =   32
      Tag             =   "P"
      Top             =   6030
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#SEMI value CHF"
      Height          =   225
      Index           =   217
      Left            =   7590
      TabIndex        =   31
      Tag             =   "P"
      Top             =   5760
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#SEMI DB%"
      Height          =   225
      Index           =   216
      Left            =   7590
      TabIndex        =   30
      Tag             =   "P"
      Top             =   5490
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#SEMI quote value"
      Height          =   225
      Index           =   215
      Left            =   7590
      TabIndex        =   29
      Tag             =   "P"
      Top             =   5220
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#SEMI area in"
      Height          =   225
      Index           =   214
      Left            =   7590
      TabIndex        =   28
      Tag             =   "P"
      Top             =   4950
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#SEMI area"
      Height          =   225
      Index           =   213
      Left            =   7590
      TabIndex        =   27
      Tag             =   "Q"
      Top             =   4680
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#SEMI system"
      Height          =   225
      Index           =   212
      Left            =   7590
      TabIndex        =   26
      Tag             =   "C"
      Top             =   4410
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#STD prime margin"
      Height          =   225
      Index           =   211
      Left            =   7590
      TabIndex        =   25
      Tag             =   "P"
      Top             =   4140
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#STD value CHF"
      Height          =   225
      Index           =   210
      Left            =   7590
      TabIndex        =   24
      Tag             =   "Q"
      Top             =   3870
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#STD DB%"
      Height          =   225
      Index           =   209
      Left            =   7590
      TabIndex        =   23
      Tag             =   "C"
      Top             =   3600
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#STD quote value"
      Height          =   225
      Index           =   208
      Left            =   7590
      TabIndex        =   22
      Tag             =   "P"
      Top             =   3330
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#STD area in"
      Height          =   225
      Index           =   207
      Left            =   7590
      TabIndex        =   21
      Tag             =   "P"
      Top             =   3060
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#STD area"
      Height          =   225
      Index           =   206
      Left            =   7590
      TabIndex        =   20
      Tag             =   "P"
      Top             =   2790
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#STD system"
      Height          =   225
      Index           =   205
      Left            =   7590
      TabIndex        =   19
      Tag             =   "P"
      Top             =   2520
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Quote sales rep"
      Height          =   225
      Index           =   204
      Left            =   7590
      TabIndex        =   18
      Tag             =   "P"
      Top             =   2250
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Quote type"
      Height          =   225
      Index           =   202
      Left            =   7590
      TabIndex        =   17
      Tag             =   "Q"
      Top             =   1710
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Quote currency"
      Height          =   225
      Index           =   201
      Left            =   7590
      TabIndex        =   16
      Tag             =   "C"
      Top             =   1440
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Quote reference"
      Height          =   225
      Index           =   200
      Left            =   7590
      TabIndex        =   15
      Tag             =   "P"
      Top             =   1170
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Customer role in project"
      Height          =   225
      Index           =   110
      Left            =   3810
      TabIndex        =   14
      Tag             =   "P"
      Top             =   3870
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Customer sales person"
      Height          =   225
      Index           =   109
      Left            =   3810
      TabIndex        =   13
      Tag             =   "Q"
      Top             =   3600
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Customer type"
      Height          =   225
      Index           =   108
      Left            =   3810
      TabIndex        =   12
      Tag             =   "C"
      Top             =   3330
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Customer fax no."
      Height          =   225
      Index           =   107
      Left            =   3810
      TabIndex        =   11
      Tag             =   "P"
      Top             =   3060
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Customer tel no."
      Height          =   225
      Index           =   106
      Left            =   3810
      TabIndex        =   10
      Tag             =   "P"
      Top             =   2790
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Customer country"
      Height          =   225
      Index           =   105
      Left            =   3810
      TabIndex        =   9
      Tag             =   "P"
      Top             =   2520
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Customer zip"
      Height          =   225
      Index           =   104
      Left            =   3810
      TabIndex        =   8
      Tag             =   "P"
      Top             =   2250
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Customer town"
      Height          =   225
      Index           =   103
      Left            =   3810
      TabIndex        =   7
      Tag             =   "P"
      Top             =   1980
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Customer address 2"
      Height          =   225
      Index           =   102
      Left            =   3810
      TabIndex        =   6
      Tag             =   "Q"
      Top             =   1710
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Customer address 1"
      Height          =   225
      Index           =   101
      Left            =   3810
      TabIndex        =   5
      Tag             =   "C"
      Top             =   1440
      Width           =   3675
   End
   Begin VB.CheckBox chk_field 
      Caption         =   "#Customer name"
      Height          =   225
      Index           =   100
      Left            =   3810
      TabIndex        =   4
      Tag             =   "P"
      Top             =   1170
      Width           =   3675
   End
   Begin VB.CommandButton btn_Selection 
      Caption         =   "..."
      Height          =   345
      Left            =   14610
      TabIndex        =   3
      Top             =   720
      Width           =   435
   End
   Begin Project1.ToolbarControl tbl_main 
      Height          =   690
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   6555
      _ExtentX        =   11562
      _ExtentY        =   1217
   End
   Begin Project1.ArmCombobox cbo_Selection 
      Height          =   345
      Left            =   9000
      TabIndex        =   1
      Tag             =   "Sel_ID"
      Top             =   720
      Width           =   5595
      _ExtentX        =   9869
      _ExtentY        =   609
   End
   Begin VB.Label lbl_label 
      Alignment       =   1  'Right Justify
      Caption         =   "#Selection"
      Height          =   225
      Index           =   40
      Left            =   6420
      TabIndex        =   2
      Tag             =   "lbl_Selection"
      Top             =   810
      Width           =   2535
   End
End
Attribute VB_Name = "SOM_ExcelExp"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Public Event OnExit()
Public Event QueryKeys(ByRef as_Keys As String, ByVal ab_SelectOnly As Boolean, ByRef ab_Cancelled As Boolean)

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

Private Const SCREEN_NAME As String = "SOM_EXCELEXP"

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



Const C_ERRORRAISE As Long = 3000

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




#If LIVE Then
    Private mo_Db                   As Object
#Else
    Private mo_Db                   As ArmDb
#End If

Private mb_Initialized              As Boolean
Private ms_LoginName                As String
Private ms_FullUserName             As String
Private ms_Language_Code            As String
Private ml_UCode                    As Long

Private mb_IsFullAccess             As Boolean

Private mb_Internal                 As Boolean

Private ms_TempTable                As String

Private ms_CoreRequest              As String
Private ms_FieldsListPlaceHolder    As String

Private ml_LocalID                  As Long
Private ml_SelList                  As Long

Private mb_IsVisible As Boolean

#If LIVE Then
Public Property Set DB(ByRef aDb As Object)
#Else
Public Property Set DB(ByRef aDb As ArmDb)
#End If
    Set mo_Db = aDb
End Property

Public Property Get Initialized() As Boolean
    Initialized = mb_Initialized
End Property

Public Property Let LoginName(ByVal aLoginName As String)
    ms_LoginName = aLoginName
End Property

Public Property Let FullUserName(ByVal aFullUserName As String)
    ms_FullUserName = aFullUserName
End Property

Public Property Let Ucode(ByVal aUcode As Long)
    ml_UCode = aUcode
End Property


Public Property Let Language_Code(ByVal aLanguage_Code As String)
    ms_Language_Code = aLanguage_Code
End Property

Public Property Let A_Visible(ByVal aVisible As Boolean)
    UserControl.Extender.Visible = aVisible
    mb_IsVisible = aVisible
End Property

Public Property Get IsVisible() As Boolean
    IsVisible = mb_IsVisible
End Property

Public Property Get A_Visible() As Boolean
    A_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

Public Sub Configure(ByVal ll_SelType As Long, ByVal as_CoreRequest As String, ByVal as_FieldsListPlaceHolder As String, ByVal ab_SelectOnly As Boolean)
On Error GoTo ErrHandler
    Debug.Assert (mb_Initialized = True)
    
    
    Call ClearForm(UserControl.Controls, Me)
    
    ms_CoreRequest = as_CoreRequest & vbCrLf & "INNER JOIN [" & ms_TempTable & "] TT ON TT.Key_ID = "
    ms_FieldsListPlaceHolder = as_FieldsListPlaceHolder
      
    ms_CoreRequest = ms_CoreRequest
      
    Select Case ll_SelType
        Case 4 'Project
            ms_CoreRequest = ms_CoreRequest & "P.Proj_ID"
        Case 5 'Quote
            ms_CoreRequest = ms_CoreRequest & "Q.Quote_ID"
        Case 6 'Customer
            ms_CoreRequest = ms_CoreRequest & "C.Cust_ID"
    End Select
      
    
    cbo_Selection.Clear
    cbo_Selection.Request = "exec SOM_cbo_SavedSelections " & ml_UCode & ", " & ll_SelType & ", '" & ms_Language_Code & "'"
    cbo_Selection.Load
    cbo_Selection.SearchItem "0", 0, , True
    ml_SelList = ll_SelType
        
    If ab_SelectOnly Then
        chk_SelectedRowsOnly.Value = vbChecked
        chk_SelectedRowsOnly.Enabled = True
    Else
        chk_SelectedRowsOnly.Value = vbUnchecked
        chk_SelectedRowsOnly.Enabled = False
    End If
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("Configure")
End Sub
Private Sub Load_SelectionSrzFields(ByRef aControls As Variant, ByRef aContainer As Object, ByVal as_SrzField As String)
On Error GoTo ErrHandler
    
    mb_Internal = True
    
    Dim lIdx As Long, lCount As Long, lControl As Object
    Dim lValues As Variant
    Dim ls_TempTag As String
    
    as_SrzField = SEP & as_SrzField & SEP
    
    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"
                    ls_TempTag = lControl.Tag & SEP
                    lValues = Split(ls_TempTag, SEP)
                    
                    If InStr(1, as_SrzField, SEP & lValues(0) & SEP, vbTextCompare) Then
                        lControl.Value = vbChecked
                    End If
            End Select
        End If
        
        Set lControl = Nothing
    Next
    mb_Internal = False
    Exit Sub
ErrHandler:
    Call ErrorHandler("Load_SelectionSrzFields")
End Sub

Public Function Load_A_COM() As Boolean

On Error GoTo ErrHandler

    If mb_Initialized Then Exit Function
    
    Call LockScreen(True)
    
    mb_IsFullAccess = SOM_lib.IsFullAccess
    ml_LocalID = GetLCIDFromCodePage(Get_Code_Page)
    
    Call Components_Settings
    
    Call InitComponents
    
    ms_TempTable = "#SOM_" & ml_UCode & "_" & UserControl.hwnd
    
    If Not mo_Db.ExecuteSQL("CREATE TABLE " + ms_TempTable + "(Key_ID int)") Then
         Err.Raise C_ERRORRAISE + 500, , "Enable to create the temporary table " & ms_TempTable & " - " & Join(mo_Db.SQLErrorMessages, vbCrLf)
    End If
    
    Call LoadAllLabels
    
    Call LockScreen(False)
    
    mb_Initialized = True

    
    Load_A_COM = True
    
    Exit Function

ErrHandler:
    LockScreen (False)
    Call ErrorHandler("Load_A_Com")
End Function
Private Function Get_Code_Page() As Long
On Error GoTo ErrHandler

    Const Request As String = "SELECT Code_Page FROM Language WHERE Language_code = '$Language_code$'"
    
    Static lb_HasRun As Boolean
    Static ls_code_page As Long

    
    
    Dim ls_req As String
    Dim ll_curs As Long
    If Not lb_HasRun Then
        ls_req = Replace(Request, "$Language_code$", ms_Language_Code, , , vbTextCompare)
        
        ll_curs = OpenSQLSafe(mo_Db, ls_req)
        
        If mo_Db.RowCount(ll_curs) = 0 Then
             Err.Raise C_ERRORRAISE + 503, , "Enable to get the code page for the language " & ms_Language_Code & " - " & Join(mo_Db.SQLErrorMessages, vbCrLf)
        End If
        
        ls_code_page = mo_Db.GetFields(ll_curs, "Code_Page")
        
        mo_Db.Close (ll_curs)
    End If
    
    Get_Code_Page = ls_code_page
    
    
    Exit Function

ErrHandler:
    mo_Db.Close (ll_curs)
    Call ErrorHandler("Get_Code_Page")
End Function


Private Sub Components_Settings()
On Error GoTo ErrHandler
    
'Nov 07; Task 469: switch first name & last name
    
    Call Component_SetUp(tbl_main, "", 76)
    
    Call Component_SetUp(SOM_Selection, "", 75)
    
    Call Component_SetUp(btn_selectAll, "btn_selectAll", 74)
    
    Call Component_SetUp(chk_SelectedRowsOnly, "SelectedRowsOnly", 73)
       
'Call Component_SetUp(chk_field(239), "StatusDate" & SEP & "Q.StatusDate", 72)
'Call Component_SetUp(chk_field(238), "Q_Status" & SEP & "AR_STAT.RF_desc 'Q_Status'", 71)
'Call Component_SetUp(chk_field(237), "Q_Last_Upd_User" & SEP & "GP_Q_LUPD.P_First_Name + ' ' + GP_Q_LUPD.P_Name 'Q_Last_Upd_User'", 70)
'Call Component_SetUp(chk_field(236), "Q_Z_last_upd" & SEP & "Q.Z_last_upd 'Q_Z_last_upd'", 69)
'Call Component_SetUp(chk_field(235), "Q_Creator" & SEP & "GP_Q_CREA.P_First_Name + ' ' + GP_Q_CREA.P_Name 'Q_Creator'", 68)
'Call Component_SetUp(chk_field(234), "Q_Creation" & SEP & "Q.Z_creation 'Q_Creation'", 67)
'Call Component_SetUp(chk_field(233), "BO_Person" & SEP & "GP_BO.P_First_Name + ' ' + GP_BO.P_Name 'BO_Person'", 66)
'Call Component_SetUp(chk_field(232), "RL_desc" & SEP & "RL.RL_desc", 65)
'Call Component_SetUp(chk_field(231), "Quote_FRGHTCost_CHF" & SEP & "Q.Quote_FRGHTCost_CHF", 64)
'Call Component_SetUp(chk_field(230), "FRGH_CURR_desc" & SEP & "CURR_FRGH.CURR_desc 'FRGH_CURR_desc'", 63)
'Call Component_SetUp(chk_field(229), "Quote_FRGHTCostLC" & SEP & "Q.Quote_FRGHTCostLC", 62)
'Call Component_SetUp(chk_field(228), "Quote_ValidToDate" & SEP & "Q.Quote_ValidToDate", 61)
'Call Component_SetUp(chk_field(227), "TOT_Quote_PrimeMargin" & SEP & "Q.TOT_Quote_PrimeMargin", 60)
'Call Component_SetUp(chk_field(226), "TOT_Quote_Value_CHF" & SEP & "Q.TOT_Quote_Value_CHF", 59)
'Call Component_SetUp(chk_field(225), "TOT_Quote_DB" & SEP & "Q.TOT_Quote_DB", 58)
'Call Component_SetUp(chk_field(224), "CUS_Quote_PrimeMargin" & SEP & "Q.CUS_Quote_PrimeMargin", 57)
'Call Component_SetUp(chk_field(223), "CUS_Quote_Value_CHF" & SEP & "Q.CUS_Quote_Value_CHF", 56)
'Call Component_SetUp(chk_field(222), "CUS_Quote_DB" & SEP & "Q.CUS_Quote_DB", 55)
'Call Component_SetUp(chk_field(221), "CUS_Quote_ValueLC" & SEP & "Q.CUS_Quote_ValueLC", 54)
'Call Component_SetUp(chk_field(220), "CUS_UM_desc" & SEP & "UMQ_CUS.UM_desc 'CUS_UM_desc'", 53)
'Call Component_SetUp(chk_field(219), "CUS_Quote_Area" & SEP & "Q.CUS_Quote_Area", 52)
'Call Component_SetUp(chk_field(218), "CUS_SS_desc" & SEP & "SS_CUS.SS_desc 'CUS_SS_desc'", 51)
'Call Component_SetUp(chk_field(217), "SEM_Quote_PrimeMargin" & SEP & "Q.SEM_Quote_PrimeMargin", 50)
'Call Component_SetUp(chk_field(216), "SEM_Quote_Value_CHF" & SEP & "Q.SEM_Quote_Value_CHF", 49)
'Call Component_SetUp(chk_field(215), "SEM_Quote_DB" & SEP & "Q.SEM_Quote_DB", 48)
'Call Component_SetUp(chk_field(214), "SEM_Quote_ValueLC" & SEP & "Q.SEM_Quote_ValueLC", 47)
'Call Component_SetUp(chk_field(213), "SEM_UM_desc" & SEP & "UMQ_SEM.UM_desc 'SEM_UM_desc'", 46)
'Call Component_SetUp(chk_field(212), "SEM_Quote_Area" & SEP & "Q.SEM_Quote_Area", 45)
'Call Component_SetUp(chk_field(211), "SEM_SS_desc" & SEP & "SS_SEM.SS_desc 'SEM_SS_desc'", 44)
'Call Component_SetUp(chk_field(210), "STD_Quote_PrimeMargin" & SEP & "Q.STD_Quote_PrimeMargin", 43)
'Call Component_SetUp(chk_field(209), "STD_Quote_Value_CHF" & SEP & "Q.STD_Quote_Value_CHF", 42)
'Call Component_SetUp(chk_field(208), "STD_Quote_DB" & SEP & "Q.STD_Quote_DB", 41)
'Call Component_SetUp(chk_field(207), "STD_Quote_ValueLC" & SEP & "Q.STD_Quote_ValueLC", 40)
'Call Component_SetUp(chk_field(206), "STD_UM_desc" & SEP & "UMQ_STD.UM_desc 'STD_UM_desc'", 39)
'Call Component_SetUp(chk_field(205), "STD_Quote_Area" & SEP & "Q.STD_Quote_Area", 38)
'Call Component_SetUp(chk_field(204), "STD_SS_desc" & SEP & "SS_STD.SS_desc 'STD_SS_desc'", 37)
'Call Component_SetUp(chk_field(203), "Q_Sales_Person" & SEP & "GP_Q.P_First_Name + ' ' + GP_Q.P_Name 'Q_Sales_Person'", 36)

Call Component_SetUp(chk_field(242), "TOT_Quote_ValueLC" & SEP & "(Q.STD_Quote_ValueLC + Q.SEM_Quote_ValueLC + Q.CUS_Quote_ValueLC) 'TOT_Quote_ValueLC'", 78)
Call Component_SetUp(chk_field(241), "Quote_OfferDate" & SEP & "Q.Quote_OfferDate", 77)
Call Component_SetUp(chk_field(240), "StatusDate" & SEP & "Q.StatusDate", 73)
Call Component_SetUp(chk_field(239), "Q_Status" & SEP & "AR_STAT.RF_desc 'Q_Status'", 72)
Call Component_SetUp(chk_field(238), "Q_Last_Upd_User" & SEP & "GP_Q_LUPD.P_Name + ' ' + GP_Q_LUPD.P_First_Name 'Q_Last_Upd_User'", 71)
Call Component_SetUp(chk_field(237), "Q_Z_last_upd" & SEP & "Q.Z_last_upd 'Q_Z_last_upd'", 70)
Call Component_SetUp(chk_field(236), "Q_Creator" & SEP & "GP_Q_CREA.P_Name + ' ' + GP_Q_CREA.P_First_Name 'Q_Creator'", 69)
Call Component_SetUp(chk_field(235), "Q_Creation" & SEP & "Q.Z_creation 'Q_Creation'", 68)
Call Component_SetUp(chk_field(234), "BO_Person" & SEP & "GP_BO.P_Name + ' ' + GP_BO.P_First_Name 'BO_Person'", 67)
Call Component_SetUp(chk_field(233), "RL_desc" & SEP & "RL.RL_desc", 66)
Call Component_SetUp(chk_field(232), "Quote_FRGHTCost_CHF" & SEP & "Q.Quote_FRGHTCost_CHF", 65)
Call Component_SetUp(chk_field(231), "FRGH_CURR_desc" & SEP & "CURR_FRGH.CURR_code 'FRGH_CURR_code'", 64)
Call Component_SetUp(chk_field(230), "Quote_FRGHTCostLC" & SEP & "Q.Quote_FRGHTCostLC", 63)
Call Component_SetUp(chk_field(229), "Quote_ValidToDate" & SEP & "Q.Quote_ValidToDate", 62)
Call Component_SetUp(chk_field(228), "TOT_Quote_PrimeMargin" & SEP & "Q.TOT_Quote_PrimeMargin", 61)
Call Component_SetUp(chk_field(227), "TOT_Quote_Value_CHF" & SEP & "Q.TOT_Quote_Value_CHF", 60)
Call Component_SetUp(chk_field(226), "TOT_Quote_DB" & SEP & "Q.TOT_Quote_DB", 59)
Call Component_SetUp(chk_field(225), "CUS_Quote_PrimeMargin" & SEP & "Q.CUS_Quote_PrimeMargin", 58)
Call Component_SetUp(chk_field(224), "CUS_Quote_Value_CHF" & SEP & "Q.CUS_Quote_Value_CHF", 57)
Call Component_SetUp(chk_field(223), "CUS_Quote_DB" & SEP & "Q.CUS_Quote_DB", 56)
Call Component_SetUp(chk_field(222), "CUS_Quote_ValueLC" & SEP & "Q.CUS_Quote_ValueLC", 55)
Call Component_SetUp(chk_field(221), "CUS_UM_desc" & SEP & "UMQ_CUS.UM_desc 'CUS_UM_code'", 54)
Call Component_SetUp(chk_field(220), "CUS_Quote_Area" & SEP & "Q.CUS_Quote_Area", 53)
Call Component_SetUp(chk_field(219), "CUS_SS_desc" & SEP & "SS_CUS.SS_desc 'CUS_desc'", 52)
Call Component_SetUp(chk_field(218), "SEM_Quote_PrimeMargin" & SEP & "Q.SEM_Quote_PrimeMargin", 51)
Call Component_SetUp(chk_field(217), "SEM_Quote_Value_CHF" & SEP & "Q.SEM_Quote_Value_CHF", 50)
Call Component_SetUp(chk_field(216), "SEM_Quote_DB" & SEP & "Q.SEM_Quote_DB", 49)
Call Component_SetUp(chk_field(215), "SEM_Quote_ValueLC" & SEP & "Q.SEM_Quote_ValueLC", 48)
Call Component_SetUp(chk_field(214), "SEM_UM_desc" & SEP & "UMQ_SEM.UM_desc 'SEM_UM_code'", 47)
Call Component_SetUp(chk_field(213), "SEM_Quote_Area" & SEP & "Q.SEM_Quote_Area", 46)
Call Component_SetUp(chk_field(212), "SEM_SS_desc" & SEP & "SS_SEM.SS_desc 'SEM_desc'", 45)
Call Component_SetUp(chk_field(211), "STD_Quote_PrimeMargin" & SEP & "Q.STD_Quote_PrimeMargin", 44)
Call Component_SetUp(chk_field(210), "STD_Quote_Value_CHF" & SEP & "Q.STD_Quote_Value_CHF", 43)
Call Component_SetUp(chk_field(209), "STD_Quote_DB" & SEP & "Q.STD_Quote_DB", 42)
Call Component_SetUp(chk_field(208), "STD_Quote_ValueLC" & SEP & "Q.STD_Quote_ValueLC", 41)
Call Component_SetUp(chk_field(207), "STD_UM_desc" & SEP & "UMQ_STD.UM_code 'STD_UM_code'", 40)
Call Component_SetUp(chk_field(206), "STD_Quote_Area" & SEP & "Q.STD_Quote_Area", 39)
Call Component_SetUp(chk_field(205), "STD_SS_desc" & SEP & "SS_STD.SS_desc 'STD_desc'", 38)
Call Component_SetUp(chk_field(204), "Q_Sales_Person" & SEP & "GP_Q.P_Name + ' ' + GP_Q.P_First_Name 'Q_Sales_Person'", 37)
Call Component_SetUp(chk_field(203), "Q_Include" & SEP & "AR_INCL.RF_desc 'Q_Include'", 36)
Call Component_SetUp(chk_field(202), "Q_Type" & SEP & "AR_TYPE.RF_desc 'Q_Type'", 35)
Call Component_SetUp(chk_field(201), "Q_Curr_desc" & SEP & "CURR_Q.CURR_code 'Q_Curr_code'", 34)
Call Component_SetUp(chk_field(200), "Q_Reference" & SEP & "P_Q.ProjectNumber + '.' + cast(Q.Quote_Ref as varchar(50)) + CASE  Q.Quote_Revision WHEN '' THEN Quote_Revision ELSE '.' + Q.Quote_Revision END 'Q_Reference'", 33)

Call Component_SetUp(chk_field(110), "C_SCT_role" & SEP & "SCT_PCL.SCT_desc 'C_SCT_role'", 32)
Call Component_SetUp(chk_field(109), "C_Sales_Person" & SEP & "GP_C.P_Name + ' ' + GP_C.P_First_Name 'C_Sales_Person'", 31)
Call Component_SetUp(chk_field(108), "C_SCT_desc" & SEP & "SCT_C.SCT_desc 'C_SCT_desc'", 30)
Call Component_SetUp(chk_field(107), "Cust_fax" & SEP & "C.Cust_fax", 29)
Call Component_SetUp(chk_field(106), "Cust_tel" & SEP & "C.Cust_tel", 28)
Call Component_SetUp(chk_field(105), "C_CT_desc" & SEP & "CT_C.CT_desc 'C_CT_desc'", 27)
Call Component_SetUp(chk_field(104), "Cust_zip" & SEP & "C.Cust_zip", 26)
Call Component_SetUp(chk_field(103), "Cust_town" & SEP & "C.Cust_town", 25)
Call Component_SetUp(chk_field(102), "Cust_addr2" & SEP & "C.Cust_addr2", 24)
Call Component_SetUp(chk_field(101), "Cust_addr1" & SEP & "C.Cust_addr1", 23)
Call Component_SetUp(chk_field(100), "Cust_name" & SEP & "C.Cust_name", 22)
Call Component_SetUp(chk_field(19), "Cf_desc" & SEP & "CF.Cf_desc", 21)
Call Component_SetUp(chk_field(18), "Proj_i5Ref" & SEP & "P.Proj_i5Ref", 20)
Call Component_SetUp(chk_field(17), "P_Last_upd_user" & SEP & "GP_P_LUPD.P_Name + ' ' + GP_P_LUPD.P_First_Name 'P_Last_upd_user'", 19)
Call Component_SetUp(chk_field(16), "P_Last_Upd" & SEP & "P.Z_last_upd 'P_Last_Upd'", 18)
Call Component_SetUp(chk_field(15), "P_Creator" & SEP & "GP_P_CREA.P_Name + ' ' + GP_P_CREA.P_First_Name 'P_Creator'", 17)
Call Component_SetUp(chk_field(14), "P_Creation" & SEP & "P.Z_creation 'P_Creation'", 16)
Call Component_SetUp(chk_field(13), "Proj_duration" & SEP & "P.Proj_duration", 15)
Call Component_SetUp(chk_field(12), "Proj_Exporderdate" & SEP & "P.Proj_Exporderdate", 14)
Call Component_SetUp(chk_field(11), "Proj_Followupdate" & SEP & "P.Proj_Followupdate", 13)
Call Component_SetUp(chk_field(10), "P_UM_desc" & SEP & "UM_P.UM_code 'P_UM_code'", 12)
Call Component_SetUp(chk_field(9), "Proj_Size" & SEP & "P.Proj_Size", 11)
Call Component_SetUp(chk_field(8), "P_Sales_person" & SEP & "GP_P.P_Name + ' ' + GP_P.P_First_Name 'P_Sales_person'", 10)
Call Component_SetUp(chk_field(7), "MKS_desc" & SEP & "MS.MKS_desc", 9)
Call Component_SetUp(chk_field(6), "PS_desc" & SEP & "PS.PS_desc", 8)
Call Component_SetUp(chk_field(5), "P_CT_desc" & SEP & "CT_P.CT_desc 'P_CT_desc'", 7)
Call Component_SetUp(chk_field(4), "Proj_Zip" & SEP & "P.Proj_Zip", 6)
Call Component_SetUp(chk_field(3), "Proj_Town" & SEP & "P.Proj_Town", 5)
Call Component_SetUp(chk_field(2), "Proj_Addr1" & SEP & "P.Proj_Addr1", 4)
Call Component_SetUp(chk_field(1), "Proj_Name" & SEP & "P.Proj_Name ", 3)
Call Component_SetUp(chk_field(0), "ProjectNumber" & SEP & "P.ProjectNumber", 2)

    
    Call Component_SetUp(btn_Selection, "", 1)
    
    Call Component_SetUp(lbl_Label(40), "lbl_Selection")
    Call Component_SetUp(cbo_Selection, "Sel_ID", 0)
    
    Exit Sub
    
ErrHandler:
    Call ErrorHandler("Components_Settings")
End Sub


Private Sub Component_SetUp(ByVal ao_cpt As Object, ByVal as_Tag As String, Optional ai_TabIndex As Integer)

On Error GoTo ErrHandler
    
    ao_cpt.Tag = as_Tag
    ao_cpt.TabIndex = ai_TabIndex
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("Component_SetUp")
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
        atlb_Toolbar.Redraw = False
        'here we can hidde buttons
        'atlb_Toolbar.ButtonVisible("C") = False
        atlb_Toolbar.Redraw = True
    End If
    atlb_Toolbar.Visible = True
    
    Exit Sub
    
ErrHandler:
    Call ErrorHandler("HandleToolbar")
    
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
    
    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 tbl_main.Load_A_COM
    tbl_main.Language = "E" 'ms_Language_Code
    
    Call tbl_main.SetToolbarInfoStringParameters(ls_Toolbar_Info, "051")
    Call HandleToolbar(tbl_main, "0", mb_IsFullAccess)
    
    Dim lo_Control As Control
    Dim ll_Charset As Long
    
    ll_Charset = GetCharSetFromCodePage(Get_Code_Page)

    For Each lo_Control In UserControl.Controls
        Select Case UCase(TypeName(lo_Control))
            Case "ARMGRID"
                Set lo_Control.ArmDb = mo_Db
                lo_Control.Font.Name = "Arial"
                lo_Control.Font.Charset = ll_Charset
                lo_Control.LocalID = ml_LocalID
                lo_Control.Codepage = Get_Code_Page
                lo_Control.Load_A_COM
                
            Case "ARMCOMBOBOX"
                Set lo_Control.ArmDb = mo_Db
                lo_Control.Font.Name = "Arial"
                lo_Control.Font.Charset = ll_Charset
                lo_Control.Load_A_COM
                
            Case "CHECKBOX", "LABEL", "COMMANDBUTTON", "FRAME"
                lo_Control.Font.Name = "Arial"
                lo_Control.Font.Charset = ll_Charset
        End Select
    Next
    SOM_Selection.Visible = False
    
    Exit Sub
    
ErrHandler:
    mo_Db.Close (lCursTB)
    Call ErrorHandler("InitComponents")
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

Public Function Unload_A_COM() As Boolean

On Error GoTo ErrHandler

    If Not mb_Initialized Then Exit Function
    
    Dim lo_Control As Control
    
    For Each lo_Control In UserControl.Controls
        Select Case UCase(TypeName(lo_Control))
            Case "TOOLBARCONTROL", "ARMCOMBOBOX", "ARMGRID"
                lo_Control.Unload_A_COM
        End Select
    Next

    If Not mo_Db.ExecuteSQL("DROP TABLE " & ms_TempTable) Then
        Err.Raise C_ERRORRAISE + 501, , "Enable to drop the temporary table " & ms_TempTable & " - " & Join(mo_Db.SQLErrorMessages, vbCrLf)
    End If
           
    Set mo_Db = Nothing
    
    mb_Initialized = False
    
    Unload_A_COM = True
    
    Exit Function
    
ErrHandler:
    Call ErrorHandler("Unload_A_Com")
End Function

Private Sub ErrorHandler(ByVal as_Fct As String)
    Err.Raise Err.Number, UserControl.Name & "." & UserControl.Ambient.DisplayName & "::" & as_Fct & SEP1 & Err.Source, Err.Description
End Sub

' logs message to database
Private Sub LogMessage(ByVal as_logMsg As String, Optional ByVal as_logType As String = "I", Optional ab_throwException As Boolean = True)
On Error GoTo ErrHandler
Const InsertReq As String = "EXEC A_log_ins $UCODE$, '$LOGTYPE$', '$MSG$', '$APP$'"
    Dim ls_req As String
    Dim ll_Cursor As Long
    
    ls_req = Replace(InsertReq, "$UCODE$", CStr(ml_UCode))
    ls_req = Replace(ls_req, "$APP$", Left(Trim(SQLStr(SCREEN_NAME & " " & App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)), 50))
    ls_req = Replace(ls_req, "$MSG$", right(Trim(SQLStr(as_logMsg)), 4000))
    ls_req = Replace(ls_req, "$LOGTYPE$", SQLStr(as_logType), 1)
    
    Call ExecuteSQLSafe(mo_Db, ls_req)
    
    Exit Sub
    
ErrHandler:
    If ab_throwException Then Call ErrorHandler(Extender.Name & ".LogMessage - " & Err.Number & ": " & Err.Description)
End Sub
Private Function SQLStr(ByVal as_str As String) As String
    SQLStr = Replace(as_str, "'", "''")
End Function

Function MsgText(ByVal aID As Long, ByVal aLang As String, ByVal aDefault As String, Optional ByVal aInfo As Variant) As String

On Error GoTo ErrHandler

Const DB_REQ As String = "SELECT message_text FROM error_message WHERE msgid = $id$ AND Language_code = '$lang$'"

    MsgText = ""
    
    Dim lRequest As String
    lRequest = Replace(DB_REQ, "$id$", aID)
    lRequest = Replace(lRequest, "$lang$", aLang)
    Dim lData As Long
    
    lData = OpenSQLSafe(mo_Db, lRequest)
    
    Dim lBuffer As String
    lBuffer = mo_Db.GetFields(lData, "message_text")
    mo_Db.Close (lData)
    If lBuffer = "" Then lBuffer = aDefault
    
    Dim li_Idx As Integer
    If Not IsMissing(aInfo) Then
        For li_Idx = 0 To UBound(aInfo)
            lBuffer = Replace(lBuffer, aInfo(li_Idx, 0), aInfo(li_Idx, 1), , , vbTextCompare)
        Next li_Idx
    End If
    
    
    MsgText = lBuffer
    Exit Function
ErrHandler:
    mo_Db.Close (lData)
    Call ErrorHandler("MsgText")
   
End Function
' 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 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 Sub ClearForm(ByRef aControls As Variant, ByRef aContainer As Object)
On Error GoTo ErrHandler
    

    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 "TEXTBOX"
                    lControl.Text = ""
                
                Case "ARMCOMBOBOX"
                    'Set lControl.SelectedItem = Nothing
                    lControl.Clear
                    DoEvents
                    
                Case "A_CALOCX"
                    lControl.reinit_cal
                
                Case "CHECKBOX"
                    lControl.Value = vbUnchecked
                
                Case "ARMCHECKVIEW"
                    'lControl.Reset
                    
                Case "FRAME", "LABEL", "TOOLBARCONTROL", "PICTUREBOX", "COMMANDBUTTON"
                
                Case "ARMGRID"
                    lControl.ClearGrid
                    lControl.Requests = ""
                
                Case "LISTBOX"
                    lControl.ListIndex = -1
                
                Case "OPTIONBUTTON"
                    Dim lValues As Variant
                    lValues = Split(lControl.Tag, SEP)
                    lControl.Value = lValues(1)
                
                Case "TABSTRIP", "DRIVELISTBOX", "DIRLISTBOX", "FILELISTBOX"
                
                Case Else
                    Debug.Print "ClearForm " & UCase(TypeName(lControl))
            End Select
        End If
        
        Set lControl = Nothing
    Next

    Exit Sub
ErrHandler:
    Call ErrorHandler("ClearForm")
End Sub

Private Sub btn_selectAll_Click()
On Error GoTo ErrHandler
    Dim ls_Text As String
    
    
    Call AllFieldsCheckValue(vbChecked)
    
    If Not cbo_Selection.SelectedItem Is Nothing Then
        ls_Text = cbo_Selection.Text
        cbo_Selection.Locked = False
        cbo_Selection.Text = "(*) " & ls_Text
        cbo_Selection.Locked = True
    End If
    
    Exit Sub
ErrHandler:
    
    Select Case Err.Number
    Case Else
        Call LogMessage("btn_selectAll_Click: " & Err.Number & ": " & Err.Source & ": " & Err.Description, "E")
        Call MsgBox("Error during the process, Contact immediatly your IT support.", vbCritical)
        End
    End Select
    
End Sub

Private Sub AllFieldsCheckValue(ByVal al_CheckValue As Long)
On Error GoTo ErrHandler
        
    Dim lo_Control As CheckBox
    
    mb_Internal = True
    
    For Each lo_Control In chk_field
        lo_Control.Value = al_CheckValue
    Next
    
    mb_Internal = False
    
    Exit Sub

ErrHandler:
    Call ErrorHandler("AllFieldsCheckValue")
End Sub

Private Sub btn_Selection_Click()
 On Error GoTo ErrHandler
    
    Call Load_Control(SOM_Selection)
    Call SOM_Selection.Run(ml_UCode, ml_SelList, Get_SelectionSrzFields)
    SOM_Selection.Zorder
    SOM_Selection.Visible = True
    
    Exit Sub
    
ErrHandler:

    Select Case Err.Number
        
    Case Else
        Call LogMessage("btn_Selection_Click: " & Err.Number & ": " & Err.Source & ": " & Err.Description, "E")
        Call MsgBox("Error during the process, Contact immediatly your IT support.", vbCritical)
        End
    End Select
    
End Sub

Private Function Get_SelectionSrzFields() As String
On Error GoTo ErrHandler
    Dim ls_SrzFields As String
    Dim lo_Control As CheckBox
    
    Dim lValues As Variant
    Dim ls_TempTag As String
    For Each lo_Control In chk_field
        If lo_Control.Value = vbChecked Then
            ls_TempTag = lo_Control.Tag & SEP
            lValues = Split(ls_TempTag, SEP)
            ls_SrzFields = ls_SrzFields & SEP & lValues(0)
        End If
    Next
    ls_SrzFields = Trim(Mid(ls_SrzFields, Len(SEP) + 1))
        
    Get_SelectionSrzFields = ls_SrzFields
    
    Exit Function
ErrHandler:
    Call ErrorHandler("Get_SelectionSrzFields")
End Function
Private Sub Load_Control(ByVal ao_ctrl As Object)
On Error GoTo ErrHandler
    If ao_ctrl.Initialized Then Exit Sub
    Call ao_ctrl.Move(0, 0, UserControl.Width, UserControl.Height)
    ao_ctrl.Language_Code = ms_Language_Code
    ao_ctrl.Ucode = ml_UCode
    ao_ctrl.LoginName = ms_LoginName
    ao_ctrl.FullUserName = ms_FullUserName
    Set ao_ctrl.DB = mo_Db
    ao_ctrl.Load_A_COM
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("Load_Control")
End Sub

Private Sub cbo_Selection_ComboDropDown()
    cbo_Selection.AutoDroppedWidth
End Sub

Private Sub cbo_Selection_ComboItemSelected()
On Error GoTo ErrHandler
    If cbo_Selection.SelectedItem Is Nothing Then Exit Sub
    
    Call LockScreen(True)
    
    Call AllFieldsCheckValue(vbUnchecked)
    Call Load_SelectionSrzFields(UserControl.Controls, Me, cbo_Selection.SelectedItem.GetData(2))

    Call LockScreen(False)
    
    Exit Sub

ErrHandler:
    Call LockScreen(False)
    
    Select Case Err.Number
    Case Else
        Call LogMessage("cbo_Selection_ComboItemSelected: " & Err.Number & ": " & Err.Source & ": " & Err.Description, "E")
        Call MsgBox("Error during the process, Contact immediatly your IT support.", vbCritical)
        End
    End Select
   
End Sub

Private Sub chk_field_Click(Index As Integer)
On Error GoTo ErrHandler
    
    Dim ls_Text As String
    
    If mb_Internal Or cbo_Selection.SelectedItem Is Nothing Then Exit Sub
    
    ls_Text = cbo_Selection.Text
    Set cbo_Selection.SelectedItem = Nothing
    cbo_Selection.Locked = False
    cbo_Selection.Text = "(*) " & ls_Text
    cbo_Selection.Locked = True
    
    Exit Sub
    
ErrHandler:
    
    Select Case Err.Number
    Case Else
        Call LogMessage("chk_field_Click: " & Err.Number & ": " & Err.Source & ": " & Err.Description, "E")
        Call MsgBox("Error during the process, Contact immediatly your IT support.", vbCritical)
        End
    End Select
         
End Sub




Private Sub SOM_Selection_OnExit()
On Error GoTo ErrHandler
   
    
    SOM_Selection.Visible = False
    
    Exit Sub

ErrHandler:
'tas478-E Nov. 07:
    Call LogMessage("SOM_Selection_OnExit: " & Err.Number & ": " & Err.Source & ": " & Err.Description, "E", False)
    Call MsgBox("Error during the process, Contact immediatly your IT support.", vbCritical)
    End

End Sub

Private Sub SOM_Selection_OnItemAdd(ByVal ae_CptType As eComponent, ByVal al_Key As Long, ByVal as_SrzFields As String)
On Error GoTo ErrHandler
    Dim lValues As Variant
    
    lValues = Split(as_SrzFields, SEP)
    
    Call cbo_Selection.AddItem(Array(al_Key, lValues(0), Mid(as_SrzFields, InStr(1, as_SrzFields, SEP) + Len(SEP))), True)
    
    Call AllFieldsCheckValue(vbUnchecked)
    
    Call Load_SelectionSrzFields(UserControl.Controls, Me, cbo_Selection.SelectedItem.GetData(2))
    
    Exit Sub

ErrHandler:
'tas478-E Nov. 07:
    Call LogMessage("SOM_Selection_OnItemAdd: " & Err.Number & ": " & Err.Source & ": " & Err.Description, "E", False)
    Call MsgBox("Error during the process, Contact immediatly your IT support.", vbCritical)
    End
    
End Sub

Private Sub SOM_Selection_OnItemDelete(ByVal ae_CptType As eComponent, ByVal al_Key As Long)
On Error GoTo ErrHandler

    If cbo_Selection.SelectedItem Is Nothing Then
        cbo_Selection.SearchItem "0", 0, , True
    Else
        If cbo_Selection.SelectedItem.Key = al_Key Then
            cbo_Selection.SearchItem "0", 0, , True
        End If
    End If
   
    Call cbo_Selection.DeleteItemKey(al_Key)
    
    Exit Sub

ErrHandler:
'tas478-E Nov. 07:
    Call LogMessage("SOM_Selection_OnItemDelete: " & Err.Number & ": " & Err.Source & ": " & Err.Description, "E", False)
    Call MsgBox("Error during the process, Contact immediatly your IT support.", vbCritical)
    End
    
End Sub
Private Function Get_FieldsList() As String
On Error GoTo ErrHandler
    
    Dim ls_FieldsList As String
    Dim lo_Control As CheckBox
    
    Dim lValues As Variant
    Dim ls_TempTag As String
    For Each lo_Control In chk_field
        If lo_Control.Value = vbChecked Then
            ls_TempTag = lo_Control.Tag & SEP
            lValues = Split(ls_TempTag, SEP)
            ls_FieldsList = ls_FieldsList & "," & lValues(1)
        End If
    Next
    ls_FieldsList = Trim(Mid(ls_FieldsList, 2))
        
    Get_FieldsList = ls_FieldsList
    
    Exit Function

ErrHandler:
    Call ErrorHandler("Get_FieldsList")
End Function

Private Function Get_FiledsLabels() As String
On Error GoTo ErrHandler
    
    Dim ls_FieldsList As String
    Dim lo_Control As CheckBox
    
    Dim lValues As Variant
    Dim ls_TempTag As String
    For Each lo_Control In chk_field
        If lo_Control.Value = vbChecked Then
            ls_FieldsList = ls_FieldsList & SEP & Trim(lo_Control.Caption)
        End If
    Next
    ls_FieldsList = Trim(Mid(ls_FieldsList, Len(SEP) + 1))
        
    Get_FiledsLabels = ls_FieldsList
    
    Exit Function

ErrHandler:
    Call ErrorHandler("Get_FiledsLabels")
End Function

Private Sub FillInTemporaryTable(ByVal as_Keys As String)
On Error GoTo ErrHandler

    Const INS_REQ As String = "INSERT INTO $TempTable$(Key_ID) VALUES ($Key_ID$)"
    Const DEL_REQ As String = "DELETE FROM $TempTable$"
    Dim ll_Count As Long
    Dim lv_Keys As Variant
    Dim ll_NbKeys As Long
    Dim ls_req As String
    
    If right(as_Keys, 2) <> SEP Then as_Keys = as_Keys & SEP
    
    lv_Keys = Split(as_Keys, SEP)
    ll_NbKeys = UBound(lv_Keys) - 1
    
    ls_req = Replace(DEL_REQ, "$TempTable$", ms_TempTable, , , vbTextCompare)
    
    Call ExecuteSQLSafe(mo_Db, ls_req)
    
    For ll_Count = 0 To ll_NbKeys
        ls_req = Replace(INS_REQ, "$TempTable$", ms_TempTable, , , vbTextCompare)
        ls_req = Replace(ls_req, "$Key_ID$", lv_Keys(ll_Count), , , vbTextCompare)
        Call ExecuteSQLSafe(mo_Db, ls_req)
    Next ll_Count
    
    Exit Sub

ErrHandler:
    Call ErrorHandler("FillInTemporaryTable")
End Sub

Private Function ExcelExport() As Boolean

On Error GoTo ErrorHandler
#If LIVE Then
    Dim lo_ExcelApp As Object
    Dim lo_WorkBook As Object
    Dim lo_WorkSheet As Object
    Dim lo_Sheet As Object
    
#Else
    Dim lo_ExcelApp As Object
    Dim lo_WorkBook As Object
    Dim lo_WorkSheet As Object
    Dim lo_Sheet As Object
    
#End If

Dim lv_ColTitles As Variant
Dim ls_Titles As String
Dim ll_Cursor As Long

    ExcelExport = False
    
    ll_Cursor = OpenSQLSafe(mo_Db, ms_CoreRequest)
    
    If mo_Db.RowCount(ll_Cursor) = 0 Then
        Call MsgBox(MsgText(C_ERRORRAISE + 50, ms_Language_Code, "#There is no data to export. Please refresh you grid and try again"), vbInformation + vbOKOnly, "")
        Exit Function
    End If
  
    ls_Titles = Get_FiledsLabels()

    ls_Titles = StrConv(StrConv(ls_Titles, vbFromUnicode, 1033), vbUnicode, ml_LocalID)
    lv_ColTitles = Split(ls_Titles, SEP)
    
    Set lo_ExcelApp = CreateObject("Excel.Application")
        
    
    Set lo_WorkBook = lo_ExcelApp.Workbooks.Add
    Set lo_WorkSheet = lo_WorkBook.Worksheets(1)
    lo_ExcelApp.Application.Visible = True
    lo_WorkSheet.Application.Visible = True
    
    lo_ExcelApp.ScreenUpdating = False
    lo_ExcelApp.Cursor = 2
    Set lo_Sheet = lo_ExcelApp.ActiveSheet
    If Not (lo_Sheet Is Nothing) Then
      If IsArray(lv_ColTitles) Then
        lo_Sheet.Range(lo_Sheet.cells(1, 1), lo_Sheet.cells(1, UBound(lv_ColTitles) + 1)) = lv_ColTitles
      End If
    End If

    Dim lv_Data As Variant
    Dim lv_Value As Variant
    Dim ll_Row As Long
    Dim ll_Col As Long
    Dim ll_nbcol As Long
    
    Dim ll_NbRows As Long
    
    ll_NbRows = mo_Db.RowCount(ll_Cursor) - 1
    ll_nbcol = mo_Db.FieldCount(ll_Cursor) - 1
    
    ReDim lv_Data(ll_nbcol)
        
    For ll_Row = 0 To ll_NbRows
        For ll_Col = 0 To ll_nbcol
            lv_Data(ll_Col) = Empty
            
            lv_Value = mo_Db.GetFields(ll_Cursor, ll_Col)
            
            Select Case mo_Db.GetFieldType(ll_Cursor, ll_Col)
            Case 129
                If ml_LocalID <> 0 Then
                  lv_Data(ll_Col) = "'" & StrConv(StrConv(lv_Value, vbFromUnicode, 1033), vbUnicode, ml_LocalID)
                Else
                  lv_Data(ll_Col) = "'" & lv_Value
                End If
            Case 7
                If lv_Value <> 0 Then
                    lv_Data(ll_Col) = lv_Value
                End If
            Case Else
                lv_Data(ll_Col) = lv_Value
            End Select
        Next ll_Col
        
        lo_Sheet.Range(lo_Sheet.cells(ll_Row + 2, 1), lo_Sheet.cells(ll_Row + 2, UBound(lv_ColTitles) + 1)) = lv_Data
        mo_Db.Next (ll_Cursor)
    Next ll_Row
    
    
    
    mo_Db.Close (ll_Cursor)
    
    If Not (lo_ExcelApp Is Nothing) Then
        lo_ExcelApp.ScreenUpdating = True
        lo_ExcelApp.Cursor = -4143
        Set lo_Sheet = Nothing
        Set lo_ExcelApp = Nothing
    End If
    
    Exit Function
ErrorHandler:
    mo_Db.Close (ll_Cursor)
    
    If Not (lo_ExcelApp Is Nothing) Then
        lo_ExcelApp.ScreenUpdating = True
        lo_ExcelApp.Cursor = -4143
        If Not (lo_WorkBook Is Nothing) Then
            lo_WorkBook.Close (False)
        End If
        Call lo_ExcelApp.quit
        Set lo_WorkSheet = Nothing
        Set lo_WorkBook = Nothing
        Set lo_Sheet = Nothing
        Set lo_ExcelApp = Nothing
    End If
    
    Call ErrorHandler("ExcelExport")
End Function
Private Sub ValidateScreen()
On Error GoTo ErrHandler
    
    Dim ls_FieldsList As String
    Dim ls_Keys As String
    Dim lb_SelectOnly As Boolean
    Dim lb_Cancelled As Boolean
    
    lb_SelectOnly = False
    lb_Cancelled = False
    
    ls_FieldsList = Get_FieldsList
    
    If ls_FieldsList = "" Then
        Call MsgBox(MsgText(2407, ms_Language_Code, "#At least one item must be checked."), vbInformation + vbOKOnly, "")
        Exit Sub
    End If
    
   
    ms_CoreRequest = Replace(ms_CoreRequest, ms_FieldsListPlaceHolder, ls_FieldsList)
    
    If chk_SelectedRowsOnly.Value = vbChecked Then lb_SelectOnly = True
    
    RaiseEvent QueryKeys(ls_Keys, lb_SelectOnly, lb_Cancelled)
    
    If lb_Cancelled Then
        RaiseEvent OnExit
        Exit Sub
    End If
    
    Call FillInTemporaryTable(ls_Keys)
    
    Call ExcelExport
    
    RaiseEvent OnExit
    
    Exit Sub

ErrHandler:
    Call ErrorHandler("ValidateScreen")
End Sub
Private Sub LoadAllLabels()
    
On Error GoTo ErrHandler
    
    Call LoadLabels(UserControl.Controls, Me, SCREEN_NAME, ms_Language_Code)
    Exit Sub
    
ErrHandler:
    Call ErrorHandler("LoadAllLabels")
 
End Sub


Public Sub LoadLabels(ByRef aControls As Variant, ByRef av_Container 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, lb_Apply As Boolean, lv_Iter As Object, ls_Buffer As String
    Dim lControl As Control, ll_Idx2 As Long, ll_Count2 As Long, ll_IdxGrd As Long
    
    'lLabels = mo_Db.OpenSQL("exec Screen_Csts '" & as_ScreenName & "','" & as_Language & "'")
    lLabels = OpenSQLSafe(mo_Db, "exec Screen_Csts '" & as_ScreenName & "','" & as_Language & "'")
    lCount = aControls.Count - 1
    
    For lIdx = 0 To lCount
        Set lControl = aControls.Item(lIdx)
        
        If Not av_Container Is Nothing Then
            lb_Apply = HasContainer(lControl, av_Container)
        Else
            lb_Apply = True
        End If
        If lb_Apply Then
            Select Case UCase(TypeName(lControl))
                Case "LABEL", "FRAME", "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 "CHECKBOX"
                    If lControl.Tag <> "" Then
                        ls_Buffer = Split(lControl.Tag, SEP, , vbTextCompare)(0)
                        If mo_Db.Find(lLabels, "FIELD_NAME", ls_Buffer, , 1) >= 0 Then
                            lControl.Caption = mo_Db.GetFields(lLabels, "LOCAL_TEXT")
                        End If
                    End If
                Case "TEXTBOX"
                    If lControl.Tag <> "" Then
                        If mo_Db.Find(lLabels, "FIELD_NAME", lControl.Tag, , 1) >= 0 Then
                            lControl.Text = mo_Db.GetFields(lLabels, "LOCAL_TEXT")
                        End If
                    End If
                Case "TABSTRIP"
                    If lControl.Tag <> "" Then
                        For Each lv_Iter In lControl.Tabs
                            If mo_Db.Find(lLabels, "FIELD_NAME", lControl.Tag & "_" & lv_Iter.Tag, , 1) >= 0 Then
                                lv_Iter.Caption = mo_Db.GetFields(lLabels, "LOCAL_TEXT")
                            End If
                        Next
                    End If
                
                Case "OPTIONBUTTON"
                    If lControl.Tag <> "" Then
                        ls_Buffer = Split(lControl.Tag, SEP, , vbTextCompare)(0)
                        On Error Resume Next
                        ls_Buffer = ls_Buffer & lControl.Index
                        On Error GoTo 0
                        If mo_Db.Find(lLabels, "FIELD_NAME", ls_Buffer, , 1) >= 0 Then
                            lControl.Caption = mo_Db.GetFields(lLabels, "LOCAL_TEXT")
                        End If
                    End If
                
                Case "ARMGRID"
                    If lControl.Tag <> "" Then
                        If mo_Db.Find(lLabels, "FIELD_NAME", lControl.Tag, , 1) >= 0 Then
                            Call lControl.LoadConstants(ptStatic, mo_Db.GetFields(lLabels, "LOCAL_TEXT"), ctColumns)
                        End If
                    End If
                    
                Case "FRAME", "MSFLEXGRID", "TOOLBARCONTROL", "COMMANDBUTTON", "ARMCHECKVIEW", "ARMCOMBOBOX", "A_CALOCX", "ARMTREEVIEW", "LISTBOX", "PICTUREBOX"
                   ' NOTHING
                
            End Select
        End If
        Set lControl = Nothing
    Next
    
CleanUp:
    mo_Db.Close (lLabels)
    Exit Sub
            
ErrHandler:
    mo_Db.Close (lLabels)
    If Not lControl Is Nothing Then Set lControl = Nothing
    Call ErrorHandler("LoadLabels")
            
End Sub

Private Sub tbl_main_action(ByVal as_Role As String, as_Language As String)
On Error GoTo ErrHandler
    Static DoCheck As Boolean
    
    If DoCheck = True Then Exit Sub
    DoCheck = True
    
    Call LockScreen(True)

    tbl_main.Enabled = False

    Select Case as_Role
        Case "H"
            Call ValidateScreen
    
        Case "T"
            RaiseEvent OnExit
    End Select
    
    tbl_main.Enabled = True
    
    Call LockScreen(False)
    
    DoCheck = False
    
    Exit Sub

ErrHandler:

    DoCheck = False

    tbl_main.Enabled = True
    
    Call LockScreen(False)
    
    Select Case Err.Number
        
    Case Else
        Call LogMessage("tbl_main_action: " & Err.Number & ": " & Err.Source & ": " & Err.Description, "E")
        Call MsgBox("Error during the process, Contact immediatly your IT support.", vbCritical)
        End
    End Select
End Sub
