1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"Application" script:
language=
"StarBasic">
4 REM =======================================================================================================================
5 REM === The Access2Base library is a part of the LibreOffice project. ===
6 REM === Full documentation is available on http://www.access2base.com ===
7 REM =======================================================================================================================
11 REM -----------------------------------------------------------------------------------------------------------------------
12 Global Const TRACEDEBUG =
"DEBUG
" ' To report values of variables
13 Global Const TRACEINFO =
"INFO
" ' To report any event
14 Global Const TRACEWARNING =
"WARNING
" ' To report some abnormal event
15 Global Const TRACEERRORS =
"ERROR
" ' To report user errors - Default value
16 Global Const TRACEFATAL =
"FATAL
" ' To report programmer errors - f.i. Wrong argument
17 Global Const TRACEABORT =
"ABORT
" ' To report Access2Base internal errors
18 Global Const TRACEANY =
"===
>" ' Always reported
19 ' ERRORs, FATALs and ABORTs are also displayed in a MsgBox (except on specific request)
20 ' FATALs and ABORTs interrupt the program execution
22 Global Const ERRINIT =
1500
23 Global Const ERRDBNOTCONNECTED =
1501
24 Global Const ERRMISSINGARGUMENTS =
1502
25 Global Const ERRWRONGARGUMENT =
1503
26 Global Const ERRMAINFORM =
1504
27 Global Const ERRMETHOD =
1505
28 Global Const ERRFILEACCESS =
1506
29 Global Const ERRFORMNOTIDENTIFIED =
1507
30 Global Const ERRFORMNOTFOUND =
1508
31 Global Const ERRFORMNOTOPEN =
1509
32 Global Const ERRDFUNCTION =
1510
33 Global Const ERROPENFORM =
1511
34 Global Const ERRPROPERTY =
1512
35 Global Const ERRPROPERTYVALUE =
1513
36 Global Const ERRINDEXVALUE =
1514
37 Global Const ERRCOLLECTION =
1515
38 Global Const ERRPROPERTYNOTARRAY =
1516
39 Global Const ERRCONTROLNOTFOUND =
1517
40 Global Const ERRNOACTIVEFORM =
1518
41 Global Const ERRDATABASEFORM =
1519
42 Global Const ERRFOCUSINGRID =
1520
43 Global Const ERRNOGRIDINFORM =
1521
44 Global Const ERRFINDRECORD =
1522
45 Global Const ERRSQLSTATEMENT =
1523
46 Global Const ERROBJECTNOTFOUND =
1524
47 Global Const ERROPENOBJECT =
1525
48 Global Const ERRCLOSEOBJECT =
1526
49 Global Const ERRMETHOD =
1527
50 Global Const ERRACTION =
1528
51 Global Const ERRSENDMAIL =
1529
52 Global Const ERRFORMYETOPEN =
1530
53 Global Const ERRPROPERTYINIT =
1531
54 Global Const ERRFILENOTCREATED =
1532
55 Global Const ERRDIALOGNOTFOUND =
1533
56 Global Const ERRDIALOGUNDEFINED =
1534
57 Global Const ERRDIALOGSTARTED =
1535
58 Global Const ERRDIALOGNOTSTARTED =
1536
59 Global Const ERRRECORDSETNODATA =
1537
60 Global Const ERRRECORDSETCLOSED =
1538
61 Global Const ERRRECORDSETRANGE =
1539
62 Global Const ERRRECORDSETFORWARD =
1540
63 Global Const ERRFIELDNULL =
1541
64 Global Const ERROVERFLOW =
1542
65 Global Const ERRNOTACTIONQUERY =
1543
66 Global Const ERRNOTUPDATABLE =
1544
67 Global Const ERRUPDATESEQUENCE =
1545
68 Global Const ERRNOTNULLABLE =
1546
69 Global Const ERRROWDELETED =
1547
70 Global Const ERRRECORDSETCLONE =
1548
71 Global Const ERRQUERYDEFDELETED =
1549
72 Global Const ERRTABLEDEFDELETED =
1550
73 Global Const ERRTABLECREATION =
1551
74 Global Const ERRFIELDCREATION =
1552
75 Global Const ERRSUBFORMNOTFOUND =
1553
76 Global Const ERRWINDOW =
1554
77 Global Const ERRCOMPATIBILITY =
1555
78 Global Const ERRPRECISION =
1556
79 Global Const ERRMODULENOTFOUND =
1557
80 Global Const ERRPROCEDURENOTFOUND =
1558
82 REM -----------------------------------------------------------------------------------------------------------------------
83 Global Const DBCONNECTBASE =
1 ' Connection from Base document (OpenConnection)
84 Global Const DBCONNECTFORM =
2 ' Connection from a database-aware form (OpenConnection)
85 Global Const DBCONNECTANY =
3 ' Connection from any document for data access only (OpenDatabase)
87 REM -----------------------------------------------------------------------------------------------------------------------
88 Global Const DBMS_UNKNOWN =
0
89 Global Const DBMS_HSQLDB1 =
1
90 Global Const DBMS_HSQLDB2 =
2
91 Global Const DBMS_FIREBIRD =
3
92 Global Const DBMS_MSACCESS2003 =
4
93 Global Const DBMS_MSACCESS2007 =
5
94 Global Const DBMS_MYSQL =
6
95 Global Const DBMS_POSTGRES =
7
96 Global Const DBMS_SQLITE =
8
98 REM -----------------------------------------------------------------------------------------------------------------------
99 Global Const COLLALLDIALOGS =
"ALLDIALOGS
"
100 Global Const COLLALLFORMS =
"ALLFORMS
"
101 Global Const COLLALLMODULES =
"ALLMODULES
"
102 Global Const COLLCOMMANDBARS =
"COMMANDBARS
"
103 Global Const COLLCOMMANDBARCONTROLS =
"COMMANDBARCONTROLS
"
104 Global Const COLLCONTROLS =
"CONTROLS
"
105 Global Const COLLFORMS =
"FORMS
"
106 Global Const COLLFIELDS =
"FIELDS
"
107 Global Const COLLPROPERTIES =
"PROPERTIES
"
108 Global Const COLLQUERYDEFS =
"QUERYDEFS
"
109 Global Const COLLRECORDSETS =
"RECORDSETS
"
110 Global Const COLLTABLEDEFS =
"TABLEDEFS
"
111 Global Const COLLTEMPVARS =
"TEMPVARS
"
113 REM -----------------------------------------------------------------------------------------------------------------------
114 Global Const OBJAPPLICATION =
"APPLICATION
"
115 Global Const OBJCOLLECTION =
"COLLECTION
"
116 Global Const OBJCOMMANDBAR =
"COMMANDBAR
"
117 Global Const OBJCOMMANDBARCONTROL =
"COMMANDBARCONTROL
"
118 Global Const OBJCONTROL =
"CONTROL
"
119 Global Const OBJDATABASE =
"DATABASE
"
120 Global Const OBJDIALOG =
"DIALOG
"
121 Global Const OBJEVENT =
"EVENT
"
122 Global Const OBJFIELD =
"FIELD
"
123 Global Const OBJFORM =
"FORM
"
124 Global Const OBJMODULE =
"MODULE
"
125 Global Const OBJOPTIONGROUP =
"OPTIONGROUP
"
126 Global Const OBJPROPERTY =
"PROPERTY
"
127 Global Const OBJQUERYDEF =
"QUERYDEF
"
128 Global Const OBJRECORDSET =
"RECORDSET
"
129 Global Const OBJSUBFORM =
"SUBFORM
"
130 Global Const OBJTABLEDEF =
"TABLEDEF
"
131 Global Const OBJTEMPVAR =
"TEMPVAR
"
133 REM -----------------------------------------------------------------------------------------------------------------------
134 Global Const CTLCONTROL =
"CONTROL
" ' ClassId
135 Global Const CTLCHECKBOX =
"CHECKBOX
" ' 5
136 Global Const CTLCOMBOBOX =
"COMBOBOX
" ' 7
137 Global Const CTLCOMMANDBUTTON =
"COMMANDBUTTON
" ' 2
138 Global Const CTLCURRENCYFIELD =
"CURRENCYFIELD
" ' 18
139 Global Const CTLDATEFIELD =
"DATEFIELD
" ' 15
140 Global Const CTLFILECONTROL =
"FILECONTROL
" ' 12
141 Global Const CTLFIXEDTEXT =
"FIXEDTEXT
" ' 10
142 Global Const CTLGRIDCONTROL =
"GRIDCONTROL
" ' 11
143 Global Const CTLGROUPBOX =
"GROUPBOX
" ' 8
144 Global Const CTLHIDDENCONTROL =
"HIDDENCONTROL
" ' 13
145 Global Const CTLIMAGEBUTTON =
"IMAGEBUTTON
" ' 4
146 Global Const CTLIMAGECONTROL =
"IMAGECONTROL
" ' 14
147 Global Const CTLLISTBOX =
"LISTBOX
" ' 6
148 Global Const CTLNAVIGATIONBAR =
"NAVIGATIONBAR
" ' 22
149 Global Const CTLNUMERICFIELD =
"NUMERICFIELD
" ' 17
150 Global Const CTLPATTERNFIELD =
"PATTERNFIELD
" ' 19
151 Global Const CTLRADIOBUTTON =
"RADIOBUTTON
" ' 3
152 Global Const CTLSCROLLBAR =
"SCROLLBAR
" ' 20
153 Global Const CTLSPINBUTTON =
"SPINBUTTON
" ' 21
154 Global Const CTLTEXTFIELD =
"TEXTFIELD
" ' 9
155 Global Const CTLTIMEFIELD =
"TIMEFIELD
" ' 16
156 REM -----------------------------------------------------------------------------------------------------------------------
157 Global Const CTLFORMATTEDFIELD =
"FORMATTEDFIELD
" ' 9 (idem TextField)
158 Global Const CTLFIXEDLINE =
"FIXEDLINE
" ' 24 (forced)
159 Global Const CTLPROGRESSBAR =
"PROGRESSBAR
" ' 23 (forced)
160 Global Const CTLSUBFORM =
"SUBFORMCONTROL
" ' None
161 REM -----------------------------------------------------------------------------------------------------------------------
162 Global Const CTLPARENTISFORM =
"FORM
"
163 Global Const CTLPARENTISDIALOG =
"DIALOG
"
164 Global Const CTLPARENTISSUBFORM =
"SUBFORM
"
165 Global Const CTLPARENTISGRID =
"GRID
"
166 Global Const CTLPARENTISGROUP =
"OPTIONGROUP
"
168 REM -----------------------------------------------------------------------------------------------------------------------
169 Global Const MODDOCUMENT =
"DOCUMENT
"
170 Global Const MODGLOBAL =
"GLOBAL
"
172 REM -----------------------------------------------------------------------------------------------------------------------
174 Document As Object
' com.sun.star.comp.dba.ODatabaseDocument or SwXTextDocument or ScModelObj
176 DbConnect As Integer
' DBCONNECTxxx constants
178 DbContainers() As Variant
' One entry by (data-aware) form
182 FormName As String
' name of data-aware form
183 Database As Object
' Database type
186 REM -----------------------------------------------------------------------------------------------------------------------
187 REM --- Next variable is initialized to empty at each macro execution start ---
188 REM --- Items in both lists correspond one by one ---
189 Public vFormNamesList As Variant
' (
0) Buffer of hierarchical form names =
> "\;
" separated values
190 ' (
1) Buffer of persistent form names =
> "\;
" separated values
192 REM -----------------------------------------------------------------------------------------------------------------------
193 Public Function AllDialogs(ByVal Optional pvIndex As Variant) As Variant
194 ' Return either a Collection or a Dialog object
195 ' The dialogs are selected only if library is loaded
197 If _ErrorHandler() Then On Local Error Goto Error_Function
198 Const cstThisSub =
"AllDialogs
"
199 Utils._SetCalledSub(cstThisSub)
201 Dim iMode As Integer, vDialogs() As Variant, i As Integer, j As Integer, iCount As Integer
202 Dim oMacLibraries As Object, vAllDialogs As Variant, oLibrary As Object, vNames() As Variant, bFound As Boolean
203 Dim oLibDialog As Object, sLibrary As String, oDocLibraries As Object, bLocalStorage As Boolean
204 Dim vLibraries() As Variant, vMacLibraries() As Variant, vDocLibraries() As Variant, oDocMacLib As Object
205 Dim vCurrentDocument As Variant
209 Const cstSepar =
"!
"
211 If IsMissing(pvIndex) Then
214 If Not Utils._CheckArgument(pvIndex,
1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
215 If VarType(pvIndex) = vbString Then iMode = cstByName Else iMode = cstByIndex
218 Set vAllDialogs = Nothing
220 Set vCurrentDocument = Nothing
221 If Not IsNull(_A2B_.CurrentDocument) Then
222 Set vCurrentDocument = _A2B_.CurrentDocument.Document
223 ElseIf Not IsNull(ThisComponent) Then
224 Set vCurrentDocument = ThisComponent
226 If IsNull(vCurrentDocument) Then
227 Set oDocLibraries = Nothing
228 vDocLibraries = Array()
230 Set oDocLibraries = vCurrentDocument.DialogLibraries
231 vDocLibraries = oDocLibraries.getElementNames()
233 Set oMacLibraries = GlobalScope.DialogLibraries
234 vMacLibraries = oMacLibraries.getElementNames()
235 'Remove Access2Base from the list
236 If _A2B_.ExcludeA2B Then
237 For i =
0 To UBound(vMacLibraries)
238 If Left(vMacLibraries(i),
11) =
"Access2Base
" Then vMacLibraries(i) =
""
241 vMacLibraries = Utils._TrimArray(vMacLibraries)
243 If UBound(vDocLibraries) + UBound(vMacLibraries)
< 0 Then
' No library
244 Set vAllDialogs = New Collect
245 Set vAllDialogs._This = vAllDialogs
246 vAllDialogs._CollType = COLLALLDIALOGS
247 vAllDialogs._Count =
0
253 For i =
0 To UBound(vDocLibraries) + UBound(vMacLibraries) +
1
255 If i
<= UBound(vDocLibraries) Then
256 sLibrary = vDocLibraries(i)
258 Set oDocMacLib = oDocLibraries
259 ' Sometimes library not loaded as should ??
260 If Not oDocMacLib.IsLibraryLoaded(sLibrary) Then oDocMacLib.loadLibrary(sLibrary)
262 sLibrary = vMacLibraries(i - UBound(vDocLibraries) -
1)
263 bLocalStorage = False
264 Set oDocMacLib = oMacLibraries
266 If oDocMacLib.IsLibraryLoaded(sLibrary) Then
267 Set oLibrary = oDocMacLib.getByName(sLibrary)
268 If oLibrary.hasElements() Then
269 vDialogs = oLibrary.getElementNames()
272 iCount = iCount + UBound(vDialogs) +
1
273 Case cstByIndex, cstByName
274 For j =
0 To UBound(vDialogs)
275 If iMode = cstByIndex Then
276 If pvIndex = iCount Then bFound = True
279 If UCase(pvIndex) = UCase(vDialogs(j)) Then bFound = True
282 Set oLibDialog = oLibrary.getByName(vDialogs(j))
' Create Dialog object
289 If bFound Then Exit For
292 If iMode = cstCount Then
293 Set vAllDialogs = New Collect
294 Set vAllDialogs._This = vAllDialogs
295 vAllDialogs._CollType = COLLALLDIALOGS
296 vAllDialogs._Count = iCount
299 If iMode = cstByIndex Then Goto Trace_Error_Index Else Goto Trace_Not_Found
301 Set vAllDialogs = New Dialog
305 ._Shortcut =
"Dialogs!
" & vDialogs(j)
306 Set ._Dialog = oLibDialog
308 ._Storage = Iif(bLocalStorage,
"DOCUMENT
",
"GLOBAL
")
313 Set AllDialogs = vAllDialogs
314 Utils._ResetCalledSub(cstThisSub)
317 TraceError(TRACEFATAL, ERRDIALOGNOTFOUND, Utils._CalledSub(),
0, , pvIndex)
320 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(),
0,
1)
321 Set vDialogs = Nothing
324 TraceError(TRACEABORT, Err, cstThisSub, Erl)
325 Set vDialogs = Nothing
327 End Function
' AllDialogs V0.9
.5
329 REM -----------------------------------------------------------------------------------------------------------------------
330 Public Function AllForms(ByVal Optional pvIndex As Variant) As Variant
331 ' Return an object of type Form indicated by either its index (integer) or its name (NOT CASE-SENSITIVE string)
332 ' Easiest use for standalone forms: AllForms(
0)
333 ' If no argument, return a Collection type
335 Const cstThisSub =
"AllForms
"
336 Dim iIndex As Integer, vReturn As Variant
337 Dim iCurrentDoc As Integer, vCurrentDoc As Variant, oForms As Variant, oCounter As Variant, oFormsCollection As Object
339 Dim vAllForms As Variant, i As Integer, vName As Variant, oDatabase As Object, bFound As Boolean
340 Const cstSeparator =
"\;
"
342 If _ErrorHandler() Then On Local Error Goto Error_Function
343 Utils._SetCalledSub(cstThisSub)
344 Set vReturn = Nothing
346 If Not IsMissing(pvIndex) Then
347 If Not Utils._CheckArgument(pvIndex,
1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
348 Select Case VarType(pvIndex)
356 iCurrentDoc = _A2B_.CurrentDocIndex()
357 If iCurrentDoc
>=
0 Then
358 vCurrentDoc = _A2B_.CurrentDocument(iCurrentDoc)
363 ' Load complete list of hierarchical and persistent names when Base document
364 If vCurrentDoc.DbConnect = DBCONNECTBASE Then vAllForms = _GetAllHierarchicalNames()
366 ' Process when NO ARGUMENT
367 If IsMissing(pvIndex) Then
' No argument
368 Set oCounter = New Collect
369 Set oCounter._This = oCounter
370 oCounter._CollType = COLLALLFORMS
371 If vCurrentDoc.DbConnect = DBCONNECTFORM Then oCounter._Count = UBound(vCurrentDoc.DbContainers) +
1 Else oCounter._Count = UBound(vAllForms) +
1
372 Set vReturn = oCounter
376 ' Process when ARGUMENT = STRING or INDEX =
> Initialize form object
377 Set ofForm = New Form
378 Set ofForm._This = ofForm
379 Select Case vCurrentDoc.DbConnect
383 If iIndex= -
1 Then
' String argument
384 vName = Utils._InList(Utils._Trim(pvIndex), vAllForms, True)
385 If vName = False Then Goto Trace_Not_Found
386 ofForm._Initialize(vName)
388 If iIndex
> UBound(vAllForms) Or iIndex
< 0 Then Goto Trace_Error_Index
' Numeric argument OK but value nonsense
389 ofForm._Initialize(vAllForms(iIndex))
395 For i =
0 To UBound(vCurrentDoc.DbContainers)
396 Set oDatabase = vCurrentDoc.DbContainers(i).Database
397 If UCase(Utils._Trim(pvIndex)) = UCase(oDatabase.FormName) Then
403 If Not bFound Then Goto Trace_Not_Found
404 ElseIf iIndex
< 0 Or iIndex
> UBound(vCurrentDoc.DbContainers) Then
405 Goto Trace_Error_Index
407 ofForm._DbEntry = iIndex
408 Set oDatabase = vCurrentDoc.DbContainers(iIndex).Database
411 vName = oDatabase.FormName
412 ofForm._DocEntry = iCurrentDoc
413 ofForm._Initialize(vName)
419 Set AllForms = vReturn
420 Utils._ResetCalledSub(cstThisSub)
423 TraceError(TRACEFATAL, ERRFORMNOTFOUND, Utils._CalledSub(),
0, , pvIndex)
426 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(),
0,
1)
427 Set vReturn = Nothing
430 TraceError(TRACEABORT, Err, cstThisSub, Erl)
431 Set vReturn = Nothing
433 End Function
' AllForms V0.9
.0
435 REM -----------------------------------------------------------------------------------------------------------------------
436 Public Function AllModules(ByVal Optional pvIndex As Variant, ByVal Optional pbAllModules As Boolean) As Variant
437 ' Return either a Collection or a Module object
438 ' The modules are selected only if library is loaded
439 ' (UNPUBLISHED) pbAllModules = False collects only the modules located in the currently open document
441 If _ErrorHandler() Then On Local Error Goto Error_Function
442 Const cstThisSub =
"AllModules
"
443 Utils._SetCalledSub(cstThisSub)
445 Dim iMode As Integer, vModules() As Variant, i As Integer, j As Integer, iCount As Integer
446 Dim oMacLibraries As Object, vAllModules As Variant, oLibrary As Object, vNames() As Variant, bFound As Boolean
447 Dim sScript As String, sLibrary As String, oDocLibraries As Object, sStorage As String
448 Dim vLibraries() As Variant, vMacLibraries() As Variant, vDocLibraries() As Variant, oDocMacLib As Object
449 Const cstCount =
0, cstByIndex =
1, cstByName =
2
450 Const cstDot =
".
"
452 If IsMissing(pvIndex) Then
455 If Not Utils._CheckArgument(pvIndex,
1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
456 If VarType(pvIndex) = vbString Then
458 ' Determine full name STORAGE.LIBRARY.MODULE
459 vNames = Split(pvIndex, cstDot)
460 If UBound(vNames) =
2 Then
461 ElseIf UBound(vNames) =
1 Then
462 pvIndex = MODDOCUMENT
& cstDot
& pvIndex
463 ElseIf UBound(vNames) =
0 Then
464 pvIndex = MODDOCUMENT
& cstDot
& "STANDARD
" & cstDot
& pvIndex
473 If IsMissing(pbAllModules) Then pbAllModules = True
474 If Not Utils._CheckArgument(pbAllModules,
2, vbBoolean) Then Goto Exit_Function
476 Set vAllModules = Nothing
478 Set oDocLibraries = _A2B_.CurrentDocument.Document.BasicLibraries
' ThisComponent.BasicLibraries
479 vDocLibraries = oDocLibraries.getElementNames()
481 Set oMacLibraries = GlobalScope.BasicLibraries
482 vMacLibraries = oMacLibraries.getElementNames()
483 'Remove Access2Base from the list
484 If _A2B_.ExcludeA2B Then
485 For i =
0 To UBound(vMacLibraries)
486 If Left(vMacLibraries(i),
11) =
"Access2Base
" Then vMacLibraries(i) =
""
489 vMacLibraries = Utils._TrimArray(vMacLibraries)
492 If UBound(vDocLibraries) + UBound(vMacLibraries)
< 0 Then
' No library
493 Set vAllModules = New Collect
494 Set vAllModules._This = vAllModules
495 vAllModules._CollType = COLLALLMODULES
496 vAllModules._Count =
0
501 For i =
0 To UBound(vDocLibraries) + UBound(vMacLibraries) +
1
503 If i
<= UBound(vDocLibraries) Then
504 sLibrary = vDocLibraries(i)
505 sStorage = MODDOCUMENT
506 Set oDocMacLib = oDocLibraries
507 ' Sometimes library not loaded as should ??
508 If Not oDocMacLib.IsLibraryLoaded(sLibrary) Then oDocMacLib.loadLibrary(sLibrary)
510 sLibrary = vMacLibraries(i - UBound(vDocLibraries) -
1)
512 Set oDocMacLib = oMacLibraries
514 If oDocMacLib.IsLibraryLoaded(sLibrary) Then
515 Set oLibrary = oDocMacLib.getByName(sLibrary)
516 If oLibrary.hasElements() Then
517 vModules = oLibrary.getElementNames()
520 iCount = iCount + UBound(vModules) +
1
521 Case cstByIndex, cstByName
522 For j =
0 To UBound(vModules)
523 If iMode = cstByIndex Then
524 If pvIndex = iCount Then bFound = True
527 If UCase(pvIndex) = UCase(sStorage
& cstDot
& sLibrary
& cstDot
& vModules(j)) Then bFound = True
530 sScript = oLibrary.getByName(vModules(j))
' Initiate Module object
538 If bFound Then Exit For
541 If iMode = cstCount Then
542 Set vAllModules = New Collect
543 Set vAllModules._This =vAllModules
544 vAllModules._CollType = COLLALLMODULES
545 vAllModules._Count = iCount
548 If iMode = cstByIndex Then Goto Trace_Error_Index Else Goto Trace_Not_Found
550 Set vAllModules = New Module
551 Set vAllModules._This = vAllModules
552 vAllModules._Name = vModules(j)
553 vAllModules._LibraryName = sLibrary
554 Set vAllModules._Library = oLibrary
555 vAllModules._Storage = sStorage
556 vAllModules._Script = sScript
557 vAllModules._Initialize()
561 Set AllModules = vAllModules
562 Utils._ResetCalledSub(cstThisSub)
565 TraceError(TRACEFATAL, ERRMODULENOTFOUND, Utils._CalledSub(),
0, , pvIndex)
568 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(),
0,
1)
569 Set vModules = Nothing
572 TraceError(TRACEABORT, Err, cstThisSub, Erl)
573 Set vModules = Nothing
575 End Function
' AllModules V1.7
.0
577 REM -----------------------------------------------------------------------------------------------------------------------
578 Public Sub CloseConnection ()
580 ' Close all connections established by current document to free memory.
581 ' - if Base document =
> close the one concerned database connection
582 ' - if non-Base documents =
> close the connections of each individual standalone form
584 If IsEmpty(_A2B_) Then Goto Exit_Sub
586 Const cstThisSub =
"CloseConnection
"
587 Utils._SetCalledSub(cstThisSub)
589 Call _A2B_.CloseConnection()
592 Utils._ResetCalledSub(cstThisSub)
594 End Sub
' CloseConnection V1.2
.0
596 REM -----------------------------------------------------------------------------------------------------------------------
597 Public Function CommandBars(Optional ByVal pvIndex As Variant, Optional ByRef poWindow As Object) As Variant
598 ' Return an object of type CommandBar indicated by its index or its name (CASE-INSENSITIVE string)
599 ' If no pvIndex argument, return a Collection type
600 ' (Unpublished) With poWindow, force the frame in which toolbars are detected
602 If _ErrorHandler() Then On Local Error Goto Error_Function
603 Const cstThisSub =
"CommandBars
"
604 Utils._SetCalledSub(cstThisSub)
606 Dim iObjectsCount As Integer, sObjectName As String, oObject As Object
607 Dim oWindow As Object, iWindowType As Integer
608 Dim i As Integer, j As Integer, k As Integer, bFound As Boolean
609 Dim sSupportedModules() As Variant, vModules() As Variant, oModuleUI As Object
610 Dim oToolbar As Object, sToolbarName As String, vUIElements() As Variant, sToolbarFullName As String, iBuiltin As Integer
612 Const cstCustom =
"CUSTOM
"
614 Set oObject = Nothing
615 If Not IsMissing(pvIndex) Then
616 If Not Utils._CheckArgument(pvIndex,
1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
622 If IsMissing(poWindow) Then Set oWindow = _SelectWindow() Else Set oWindow = poWindow
623 If IsNull(oWindow.Frame) Then Goto Trace_WindowError
625 ' List of
21 modules
626 vModules = CreateUnoService(
"com.sun.star.frame.ModuleManager
").getElementNames()
628 iWindowType = oWindow.WindowType
629 Select Case iWindowType
' Supported window types only
631 sSupportedModules = Array(
"com.sun.star.sdb.FormDesign
" )
633 sSupportedModules = Array(
"com.sun.star.script.BasicIDE
" )
634 Case acDatabaseWindow
635 sSupportedModules = Array(
"com.sun.star.sdb.OfficeDatabaseDocument
" )
637 sSupportedModules = Array(
"com.sun.star.sdb.TextReportDesign
" )
639 Select Case oWindow.DocumentType
640 Case docCalc : sSupportedModules = Array(
"com.sun.star.sheet.SpreadsheetDocument
" )
641 Case docWriter : sSupportedModules = Array(
"com.sun.star.text.TextDocument
" )
642 Case docImpress : sSupportedModules = Array(
"com.sun.star.presentation.PresentationDocument
" )
643 Case docDraw : sSupportedModules = Array(
"com.sun.star.drawing.DrawingDocument
" )
644 Case docMath : sSupportedModules = Array(
"com.sun.star.formula.FormulaProperties
" )
645 Case Else : sSupportedModules = Array()
647 Case acTable, acQuery
648 sSupportedModules = Array(
"com.sun.star.sdb.DataSourceBrowser
" _
649 ,
"com.sun.star.sdb.TableDataView
" _
652 sSupportedModules = Array(
"com.sun.star.sdb.RelationDesign
" )
654 sSupportedModules = Array(
"com.sun.star.frame.StartModule
" )
656 sSupportedModules = Array()
659 ' Find all standard and custom toolbars stored in LibO/AOO Base
660 Set oModuleUI = CreateUnoService(
"com.sun.star.ui.ModuleUIConfigurationManagerSupplier
")
661 For k =
0 To UBound(vModules)
662 For j =
0 To UBound(sSupportedModules)
663 iBuiltin =
1 ' Default = builtin
664 If vModules(k) = sSupportedModules(j) Then
' Supported modules only
665 Set oToolbar = oModuleUI.getUIConfigurationManager(vModules(k))
666 vUIElements() = oToolbar.getUIElementsInfo(
0)
667 For i =
0 To UBound(vUIElements)
668 sToolbarFullName = _GetPropertyValue(vUIElements(i),
"ResourceURL
")
669 sToolbarName = Split(sToolbarFullName,
"/
")(
2)
670 If _IsLeft(UCase(sToolbarName), UCase(cstCustom)) Then
671 sToolbarName = _GetPropertyValue(vUIElements(i),
"UIName
")
675 iObjectsCount = iObjectsCount +
1
677 Case IsMissing(pvIndex)
678 Case VarType(pvIndex) = vbString
679 If UCase(pvIndex) = UCase(sToolbarName) Then bFound = True
681 If pvIndex
< 0 Then Goto Trace_IndexError
682 If pvIndex = iObjectsCount -
1 Then bFound = True
686 Set oObject = _NewCommandBar(vModules(k), sToolbarName, sToolbarFullName, iBuiltin)
687 Set oObject._Window = oWindow.Frame
688 Set oObject._Toolbar = oToolbar
696 ' Find all (not builtin) toolbars stored in current document (typically forms)
697 iBuiltin =
3 ' Stored in form itself
698 Set oToolbar = oWindow.Frame.Controller.Model.getUIConfigurationManager
699 vUIElements() = oToolbar.getUIElementsInfo(
0)
700 For i =
0 To UBound(vUIElements)
701 sToolbarFullName = _GetPropertyValue(vUIElements(i),
"ResourceURL
")
702 sToolbarName = _GetPropertyValue(vUIElements(i),
"UIName
")
703 iObjectsCount = iObjectsCount +
1
705 Case IsMissing(pvIndex)
706 Case VarType(pvIndex) = vbString
707 If UCase(pvIndex) = UCase(sToolbarName) Then bFound = True
709 If pvIndex = iObjectsCount -
1 Then bFound = True
712 Set oObject = _NewCommandBar(
"", sToolbarName, sToolbarFullName, iBuiltin)
713 Set oObject._Window = oWindow.Frame
714 Set oObject._Toolbar = oToolbar
719 ' MISSING : CUSTOM POPUPS
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
722 Case IsMissing(pvIndex)
723 Set oObject = New Collect
724 Set oObject._This = oObject
725 oObject._CollType = COLLCOMMANDBARS
726 oObject._Count = iObjectsCount
727 Case VarType(pvIndex) = vbString
729 Case Else
' pvIndex is numeric
730 Goto Trace_IndexError
734 Set CommandBars = oObject
735 Set oObject = Nothing
736 Utils._ResetCalledSub(cstThisSub)
739 TraceError(TRACEABORT, Err, cstThisSub, Erl)
742 TraceError(TRACEFATAL, ERROBJECTNOTFOUND, Utils._CalledSub(),
0, , Array(_GetLabel(
"COMMANDBAR
"), pvIndex))
745 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(),
0)
748 TraceError(TRACEFATAL, ERRWINDOW, Utils._CalledSub(),
0)
750 End Function
' CommandBars V1,
3,
0
752 REM -----------------------------------------------------------------------------------------------------------------------
753 Public Function Controls(ByVal Optional pvObject As Variant, Optional ByVal pvIndex As Variant) As Variant
754 ' Return an object of type Control indicated by either its index (integer) or its name (CASE-INSENSITIVE string)
755 ' The
1st argument pvObject can be either
756 ' an object of type FORM (
1)
757 ' a main form name as string
758 ' an object of type SUBFORM (
2)
759 ' The Form property in the returned variant contains a SUBFORM type
760 ' an object of type CONTROL and subtype GRIDCONTROL (
3)
761 ' an object of type OPTIONGROUP (
4)
2nd argument, if any, must be numeric
762 ' If no pvIndex argument, return a Collection type
764 If _ErrorHandler() Then On Local Error Goto Error_Function
765 Dim vObject As Object
766 Const cstThisSub =
"Controls
"
767 Utils._SetCalledSub(cstThisSub)
769 If IsMissing(pvObject) Then Call _TraceArguments()
770 If IsNull(pvObject) Or IsEmpty(pvObject) Then Call _TraceArguments()
773 If VarType(pvObject) = vbString Then
774 Set vObject = Forms(pvObject)
775 If IsNull(vObject) Then Goto Exit_Function
777 If Not Utils._CheckArgument(pvObject,
1, Array(OBJFORM, OBJSUBFORM, OBJOPTIONGROUP, CTLGRIDCONTROL)) Then Goto Exit_Function
778 Set vObject = pvObject
781 If IsMissing(pvIndex) Then
782 Controls = vObject.Controls()
784 If Not Utils._CheckArgument(pvIndex,
2, Utils._AddNumeric(vbString)) Then Goto Exit_Function
785 Controls = vObject.Controls(pvIndex)
789 Utils._ResetCalledSub(cstThisSub)
792 TraceError(TRACEERROR, Err, cstThisSub, Erl)
794 End Function
' Controls V0.9
.0
796 REM -----------------------------------------------------------------------------------------------------------------------
797 Public Function CurrentDb() As Object
798 ' Returns _A2B_.CurrentDocument().Database as an object to allow access to its properties
800 Const cstThisSub =
"CurrentDb
"
801 Utils._SetCalledSub(cstThisSub)
803 Set CurrentDb = Nothing
804 If IsEmpty(_A2B_) Then GoTo Exit_Function
805 Set CurrentDb = _A2B_.CurrentDb()
808 Utils._ResetCalledSub(cstThisSub)
810 End Function
' CurrentDb V1.1
.0
812 REM -----------------------------------------------------------------------------------------------------------------------
813 Public Function CurrentUser() As String
815 Dim oPath As Object, sUser As String
817 Set oPath = CreateUnoService(
"com.sun.star.util.PathSubstitution
")
818 sUser = oPath.getSubstituteVariableValue(
"$(username)
")
' New since LibreOffice
5.2
821 End Function
' CurrentUser V0.9
.1
823 REM -----------------------------------------------------------------------------------------------------------------------
824 Public Function DAvg( _
825 ByVal Optional psExpr As String _
826 , ByVal Optional psDomain As String _
827 , ByVal Optional pvCriteria As Variant _
829 ' Return average of scope
830 Const cstThisSub =
"DAvg
"
831 Utils._SetCalledSub(cstThisSub)
832 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
833 DAvg = Application._CurrentDb()._DFunction(
"AVG
", psExpr, psDomain, Iif(IsMissing(pvCriteria),
"", pvCriteria),
"")
834 Utils._ResetCalledSub(cstThisSub)
835 End Function
' DAvg
837 REM -----------------------------------------------------------------------------------------------------------------------
838 Public Function DCount( _
839 ByVal Optional psExpr As String _
840 , ByVal Optional psDomain As String _
841 , ByVal Optional pvCriteria As Variant _
843 ' Return # of occurrences of scope
844 Const cstThisSub =
"DCount
"
845 Utils._SetCalledSub(cstThisSub)
846 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
847 DCount = Application._CurrentDb()._DFunction(
"COUNT
", psExpr, psDomain, Iif(IsMissing(pvCriteria),
"", pvCriteria),
"")
848 Utils._ResetCalledSub(cstThisSub)
849 End Function
' DCount
851 REM -----------------------------------------------------------------------------------------------------------------------
852 Public Function DLookup( _
853 ByVal Optional psExpr As String _
854 , ByVal Optional psDomain As String _
855 , ByVal Optional pvCriteria As Variant _
856 , ByVal Optional pvOrderClause As Variant _
859 ' Return a value within a table
860 'Arguments: psExpr: an SQL expression
861 ' psDomain: a table- or queryname
862 ' pvCriteria: an optional WHERE clause
863 ' pcOrderClause: an optional order clause incl.
"DESC
" if relevant
864 'Return: Value of the psExpr if found, else Null.
865 'Author: inspired from Allen Browne. http://allenbrowne.com/ser-
42.html
867 ' 1. To find the last value, include DESC in the OrderClause, e.g.:
868 ' DLookup(
"[Surname]
& [FirstName]
",
"tblClient
", ,
"ClientID DESC
")
869 ' 2. To find the lowest non-null value of a field, use the Criteria, e.g.:
870 ' DLookup(
"ClientID
",
"tblClient
",
"Surname Is Not Null
" ,
"Surname
")
872 Const cstThisSub =
"DLookup
"
873 Utils._SetCalledSub(cstThisSub)
874 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
875 DLookup = Application._CurrentDb()._DFunction(
"", psExpr, psDomain _
876 , Iif(IsMissing(pvCriteria),
"", pvCriteria) _
877 , Iif(IsMissing(pvOrderClause),
"", pvOrderClause) _
879 Utils._ResetCalledSub(cstThisSub)
880 End Function
' DLookup
882 REM -----------------------------------------------------------------------------------------------------------------------
883 Public Function DMax( _
884 ByVal Optional psExpr As String _
885 , ByVal Optional psDomain As String _
886 , ByVal Optional pvCriteria As Variant _
888 ' Return maximum of scope
889 Const cstThisSub =
"DMax
"
890 Utils._SetCalledSub(cstThisSub)
891 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
892 DMax = Application._CurrentDb()._DFunction(
"MAX
", psExpr, psDomain, Iif(IsMissing(pvCriteria),
"", pvCriteria),
"")
893 Utils._ResetCalledSub(cstThisSub)
894 End Function
' DMax
896 REM -----------------------------------------------------------------------------------------------------------------------
897 Public Function DMin( _
898 ByVal Optional psExpr As String _
899 , ByVal Optional psDomain As String _
900 , ByVal Optional pvCriteria As Variant _
902 ' Return minimum of scope
903 Const cstThisSub =
"DMin
"
904 Utils._SetCalledSub(cstThisSub)
905 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
906 DMin = Application._CurrentDb()._DFunction(
"MIN
", psExpr, psDomain, Iif(IsMissing(pvCriteria),
"", pvCriteria),
"")
907 Utils._ResetCalledSub(cstThisSub)
908 End Function
' DMin
910 REM -----------------------------------------------------------------------------------------------------------------------
911 Public Function DStDev( _
912 ByVal Optional psExpr As String _
913 , ByVal Optional psDomain As String _
914 , ByVal Optional pvCriteria As Variant _
916 ' Return standard deviation of scope
917 Const cstThisSub =
"DStDev
"
918 Utils._SetCalledSub(cstThisSub)
919 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
920 DStDev = Application._CurrentDb()._DFunction(
"STDDEV_SAMP
", psExpr, psDomain, Iif(IsMissing(pvCriteria),
"", pvCriteria),
"")
' STDDEV not STDEV !
921 Utils._ResetCalledSub(cstThisSub)
922 End Function
' DStDev
924 REM -----------------------------------------------------------------------------------------------------------------------
925 Public Function DStDevP( _
926 ByVal Optional psExpr As String _
927 , ByVal Optional psDomain As String _
928 , ByVal Optional pvCriteria As Variant _
930 ' Return standard deviation of scope
931 Const cstThisSub =
"DStDevP
"
932 Utils._SetCalledSub(cstThisSub)
933 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
934 DStDevP = Application._CurrentDb()._DFunction(
"STDDEV_POP
", psExpr, psDomain, Iif(IsMissing(pvCriteria),
"", pvCriteria),
"")
' STDDEV not STDEV !
935 Utils._ResetCalledSub(cstThisSub)
936 End Function
' DStDevP
938 REM -----------------------------------------------------------------------------------------------------------------------
939 Public Function DSum( _
940 ByVal Optional psExpr As String _
941 , ByVal Optional psDomain As String _
942 , ByVal Optional pvCriteria As Variant _
944 ' Return sum of scope
945 Const cstThisSub =
"DSum
"
946 Utils._SetCalledSub(cstThisSub)
947 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
948 DSum = Application._CurrentDb()._DFunction(
"SUM
", psExpr, psDomain, Iif(IsMissing(pvCriteria),
"", pvCriteria),
"")
949 Utils._ResetCalledSub(cstThisSub)
950 End Function
' DSum
952 REM -----------------------------------------------------------------------------------------------------------------------
953 Public Function DVar( _
954 ByVal Optional psExpr As String _
955 , ByVal Optional psDomain As String _
956 , ByVal Optional pvCriteria As Variant _
958 ' Return variance of scope
959 Const cstThisSub =
"DVar
"
960 Utils._SetCalledSub(cstThisSub)
961 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
962 DVar = Application._CurrentDb()._DFunction(
"VAR_SAMP
", psExpr, psDomain, Iif(IsMissing(pvCriteria),
"", pvCriteria),
"")
963 Utils._ResetCalledSub(cstThisSub)
964 End Function
' DVar
966 REM -----------------------------------------------------------------------------------------------------------------------
967 Public Function DVarP( _
968 ByVal Optional psExpr As String _
969 , ByVal Optional psDomain As String _
970 , ByVal Optional pvCriteria As Variant _
972 ' Return variance of scope
973 Const cstThisSub =
"DVarP
"
974 Utils._SetCalledSub(cstThisSub)
975 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
976 DVarP = Application._CurrentDb()._DFunction(
"VAR_POP
", psExpr, psDomain, Iif(IsMissing(pvCriteria),
"", pvCriteria),
"")
977 Utils._ResetCalledSub(cstThisSub)
978 End Function
' DVarP
980 REM -----------------------------------------------------------------------------------------------------------------------
981 Public Function Events(Optional poEvent As Variant) As Variant
982 ' Return an event object corresponding with actual event
984 Dim vEvent As Variant
985 If _ErrorHandler() Then On Local Error Goto Error_Function
986 Const cstThisSub =
"Events
"
987 Utils._SetCalledSub(cstThisSub)
990 If IsMissing(poEvent) Then Goto Exit_Function
991 If IsNull(poEvent) Then Goto Exit_Function
993 If Not Utils._CheckArgument(poEvent,
1, vbObject, , False) Then Goto Exit_Function
' No error handling in CheckArgument
994 If Not Utils._hasUNOProperty(poEvent,
"Source
") Then Goto Trace_Error
995 Set vEvent = New Event
996 vEvent._Initialize(poEvent)
1000 Utils._ResetCalledSub(cstThisSub)
1003 TraceError(TRACEWARNING, Err, cstThisSub, Erl)
1006 ' Errors are not displayed to avoid display infinite cycling
1007 TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(),
0, False, Array(
1, Utils._CStr(poEvent)))
1008 Set vEvent = Nothing
1010 End Function
' Events V0.9
.1
1012 REM -----------------------------------------------------------------------------------------------------------------------
1013 Public Function Forms(ByVal Optional pvIndex As Variant) As Variant
1014 ' Return an object of type Form indicated by either its index (integer) or its name (NOT CASE-SENSITIVE string)
1015 ' The concerned form must be loaded.
1016 ' If no argument, return a Collection type
1018 Const cstThisSub =
"Forms
"
1019 Utils._SetCalledSub(cstThisSub)
1020 If _ErrorHandler() Then On Local Error Goto Error_Function
1022 Dim ofForm As Object, oCounter As Variant, vForms As Variant, oIndex As Object
1023 Set vForms = Nothing
1025 Dim iCount As Integer
1026 If IsMissing(pvIndex) Then
1027 iCount = Application._CountOpenForms()
1028 Set oCounter = New Collect
1029 Set oCounter._This = oCounter
1030 oCounter._CollType = COLLFORMS
1031 oCounter._Count = iCount
1035 If Not Utils._CheckArgument(pvIndex,
1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
1038 Select Case VarType(pvIndex)
1040 Set ofForm = Application.AllForms(Utils._Trim(pvIndex))
1042 iCount = Application._CountOpenForms()
1043 If iCount
<= pvIndex Then Goto Trace_Error_Index
1044 Set ofForm = Application._CountOpenForms(pvIndex)
1047 If IsNull(ofForm) Then Goto Trace_Error
1048 If ofForm.IsLoaded Then
1051 Set vForms = Nothing
1052 TraceError(TRACEFATAL, ERRFORMNOTOPEN, Utils._CalledSub(),
0, , ofForm._Name)
1058 Utils._ResetCalledSub(cstThisSub)
1061 TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(),
0, , Array(
1, pvIndex))
1062 Set vForms = Nothing
1065 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(),
0,
1)
1066 Set vForms = Nothing
1069 TraceError(TRACEABORT, Err, cstThisSub, Erl)
1071 End Function
' Forms V0.9
.0
1073 REM -----------------------------------------------------------------------------------------------------------------------
1074 Public Function getObject(Optional pvShortcut As Variant) As Variant
1075 ' Return the object described by pvShortcut ignoring its final property
1076 ' Example:
"Forms!myForm!myControl.myProperty
" =
> Controls(Forms(
"myForm
"),
"myControl
"))
1078 Const cstEXCLAMATION =
"!
"
1079 Const cstDOT =
".
"
1081 If _ErrorHandler() Then On Local Error Goto Error_Function
1082 Const cstThisSub =
"getObject
"
1083 Utils._SetCalledSub(cstThisSub)
1084 If IsMissing(pvShortcut) Then Call _TraceArguments()
1085 If Not Utils._CheckArgument(pvShortcut,
1, vbString) Then Goto Exit_Function
1087 Dim iCurrentIndex As Integer, vCurrentObject As Variant, sCurrentProperty As String
1088 Dim sComponents() As String, sSubComponents() As String, sDialog As String
1090 Set vCurrentObject = Nothing
1091 sComponents = Split(Trim(pvShortcut), cstEXCLAMATION)
1092 If UBound(sComponents) =
0 Then Goto Trace_Error
1093 If Not Utils._InList(UCase(sComponents(
0)), Array(
"FORMS
",
"DIALOGS
",
"TEMPVARS
")) Then Goto Trace_Error
1094 If sComponents(
1) =
"0" Or Left(sComponents(
1),
2) =
"0.
" Then
1095 Set oDoc = _A2B_.CurrentDocument()
1096 If oDoc.DbConnect = DBCONNECTFORM Then sComponents(
1) = oDoc.DbContainers(
0).FormName Else Goto Trace_Error
1099 sSubComponents = Split(sComponents(UBound(sComponents)), cstDOT)
1100 sComponents(UBound(sComponents)) = sSubComponents(
0)
' Ignore final property, if any
1102 Set vCurrentObject = New Collect
1103 Set vCurrentObject._This = vCurrentObject
1104 Select Case UCase(sComponents(
0))
1105 Case
"FORMS
" : vCurrentObject._CollType = COLLFORMS
1106 Case
"DIALOGS
" : vCurrentObject._CollType = COLLALLDIALOGS
1107 Case
"TEMPVARS
" : vCurrentObject._CollType = COLLTEMPVARS
1109 For iCurrentIndex =
1 To UBound(sComponents)
' Start parsing ...
1110 sSubComponents = Split(sComponents(iCurrentIndex), cstDOT)
1111 sComponents(iCurrentIndex) = Utils._Trim(sSubComponents(
0))
1112 Select Case UBound(sSubComponents)
1114 sCurrentProperty =
""
1116 sCurrentProperty = sSubComponents(
1)
1120 Select Case vCurrentObject._Type
1122 Select Case vCurrentObject._CollType
1124 vCurrentObject = Application.AllForms(sComponents(iCurrentIndex))
1126 sDialog = UCase(sComponents(iCurrentIndex))
1127 vCurrentObject = Application.AllDialogs(sDialog)
1128 If Not vCurrentObject.IsLoaded Then Goto Trace_Error
1129 Set vCurrentObject.UnoDialog = _A2B_.Dialogs.Item(sDialog)
1131 If UBound(sComponents)
> 1 Then Goto Trace_Error
1132 vCurrentObject = Application.TempVars(sComponents(
1))
1135 Case OBJFORM, OBJSUBFORM, OBJCONTROL, OBJDIALOG
1136 vCurrentObject = vCurrentObject.Controls(sComponents(iCurrentIndex))
1138 If sCurrentProperty
<> "" Then vCurrentObject = vCurrentObject.getProperty(sCurrentProperty)
1141 Set getObject = vCurrentObject
1144 Utils._ResetCalledSub(cstThisSub)
1147 TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(),
0, , Array(
1, pvShortcut))
1150 TraceError(TRACEABORT, Err, cstThisSub, Erl)
1152 End Function
' getObject V0.9
.5
1154 REM -----------------------------------------------------------------------------------------------------------------------
1155 Public Function getValue(Optional pvObject As Variant) As Variant
1156 ' getValue also interprets shortcut strings !!
1157 Dim vItem As Variant, sProperty As String
1158 If IsMissing(pvObject) Or IsEmpty(pvObject) Then Call _TraceArguments(
"getValue
")
1159 If VarType(pvObject) = vbString Then
1160 Utils._SetCalledSub(
"getValue
")
1161 Set vItem = getObject(pvObject)
1162 sProperty = Utils._FinalProperty(pvObject)
1163 If sProperty =
"" Then sProperty =
"Value
" ' Default value if final property in shortcut is absent
1164 getValue = vItem.getProperty(sproperty)
1165 Utils._ResetCalledSub(
"getValue
")
1167 Set vItem = pvObject
1168 getValue = vItem.getProperty(
"Value
")
1170 End Function
' getValue
1172 REM -----------------------------------------------------------------------------------------------------------------------
1173 Function HtmlEncode(ByVal pvString As Variant, ByVal Optional pvLength As Variant) As String
1174 ' Converts a string to an HTML-encoded string.
1176 If _ErrorHandler() Then On Local Error Goto Error_Function
1177 Const cstThisSub =
"HtmlEncode
"
1178 Utils._SetCalledSub(cstThisSub)
1180 HtmlEncode =
""
1182 Dim sOutput As String, l As Long, lLength As Long
1183 If IsMissing(pvLength) Then pvLength =
0
1184 If Not Utils._CheckArgument(pvString,
1, vbString) Then Goto Exit_Function
1185 If Not Utils._CheckArgument(pvLength,
1, _AddNumeric()) Then Goto Exit_Function
1187 sOutput =
""
1188 lLength = CLng(pvLength)
1189 If Len(pvString)
> 0 Then
1190 For l =
1 To Len(pvString)
1191 If lLength
> 0 And Len(sOutput)
> lLength Then Exit For
1192 sOutput = sOutput
& Utils._UTF8Encode(Mid(pvString, l,
1))
1196 HtmlEncode = sOutput
1199 Utils._ResetCalledSub(cstThisSub)
1202 TraceError(TRACEABORT, Err, cstThisSub, Erl)
1204 End Function
' HtmlEncode V1.4
.0
1206 REM -----------------------------------------------------------------------------------------------------------------------
1207 Public Function OpenConnection ( _
1208 Optional pvComponent As Variant _
1209 , ByVal Optional pvUser As Variant _
1210 , ByVal Optional pvPassword As Variant _
1213 ' Establish connection with the database designated in the currently open front-end (.odb) document
1214 ' Call template:
1215 ' Call OpenConnection(ThisDatabaseDocument[,
"",
""])
1216 ' Call stored in the OpenDocument event of the front-end database document
1218 ' Initiates processing of a (standalone ?) Writer, Calc, ... document with
1 or more data-aware forms
1219 ' Call template:
1220 ' Call OpenConnection(ThisComponent[,
"",
""])
1221 ' Call stored in the OpenDocument event of the document
1223 ' User and Password arguments are obsolete (still tolerated)
1224 ' - because no mean has been found to connect protected db from .odb via API
1225 ' - because having multiple forms with multiple db
's and multiple passwords is meaningless
1227 Dim oComponent As Object, oForms As Object, iCurrent As Integer
1228 Dim i As Integer, bFound As Boolean
1229 Dim vCurrentDoc() As Variant
1230 Dim oBaseContext As Object, sDbNames() As String, oBaseSource As Object
1231 Dim sDatabaseURL As String, oHandler As Object
1232 Dim vDbContainer As Variant, vDbContainers() As Variant, vDocContainer As Variant
1233 Dim sFormName As String
1235 If IsEmpty(_A2B_) Then Call Application._RootInit()
' First use of Access2Base in current AOO/LibO session
1236 Set OpenConnection = Nothing
1238 If _ErrorHandler() Then On Local Error Goto Error_Function
1239 Const cstThisSub =
"OpenConnection
"
1240 Utils._SetCalledSub(cstThisSub)
1241 If IsMissing(pvComponent) Then Call _TraceArguments()
1242 If Not Utils._CheckArgument(pvComponent,
1, vbObject) Then Goto Exit_Function
1243 Set oComponent = pvComponent
1244 If Not Utils._hasUNOProperty(oComponent,
"ImplementationName
") Then
1245 TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(),
0,
1, Array(
1, oComponent))
1248 If IsMissing(pvUser) Then pvUser =
""
1249 If IsMissing(pvPassword) Then pvPassword =
""
1250 If Not Utils._CheckArgument(pvUser,
2, vbString) Then Goto Exit_Function
1251 If Not Utils._CheckArgument(pvPassword,
3, vbString) Then Goto Exit_Function
1253 If Not IsArray(_A2B_.CurrentDoc) Then
1254 vCurrentDoc() = Array()
1255 Redim vCurrentDoc(
0 To
0)
' Create at least one entry for database document
1257 vCurrentDoc() = _A2B_.CurrentDoc()
1260 ' Find index of entry to use for new connection
1262 Select Case .ImplementationName
1263 Case
"com.sun.star.comp.dba.ODatabaseDocument
"
1265 Case Else
' "SwXTextDocument
",
"ScModelObj
"
1266 If UBound(vCurrentDoc)
<=
0 Then
' First Calc or Writer during current session
1268 Else
' Search entry already used earlier by same component
1270 For i =
1 To UBound(vCurrentDoc)
1271 If Not IsEmpty(vCurrentDoc(i)) Then
1272 If vCurrentDoc(i).Active And vCurrentDoc(i).URL = .URL Then
1281 iCurrent = UBound(vCurrentDoc) +
1 ' No entry found, increment array
1282 ReDim Preserve vCurrentDoc(
0 To iCurrent)
1287 ' Initialize future entry
1288 Set vDocContainer = New DocContainer
1289 Set vDocContainer.Document = oComponent
1290 vDocContainer.Active = True
1291 vDocContainer.URL = oComponent.URL
1292 ' Initialize each DbContainer entry
1293 vDbContainers() = Array()
1294 TraceLog(TRACEANY, Utils._GetProductName()
& " -
" & Application.ProductCode(), False)
1295 Select Case oComponent.ImplementationName
1296 Case
"com.sun.star.comp.dba.ODatabaseDocument
" ' Ignore pvUser and pvPassword arguments
1297 vDbContainer = New DbContainer
1298 vDbContainer.FormName =
""
1299 Set vDbContainer.Database = New Database
1300 Set vDbContainer.Database._This = vDbContainer.Database
1301 With vDbContainer.Database
1302 If Not oComponent.CurrentController.IsConnected Then
1303 Set oHandler = createUnoService(
"com.sun.star.sdb.InteractionHandler
")
1304 Set .Connection = oComponent.DataSource.connectWithCompletion(oHandler)
1305 oComponent.CurrentController.connect()
1307 Set .Connection = oComponent.CurrentController.ActiveConnection
1309 vDocContainer.DbConnect = DBCONNECTBASE
1310 ._DbConnect = DBCONNECTBASE
1311 Set .MetaData = .Connection.MetaData
1313 If .MetaData.DatabaseProductName =
"MySQL
" Then
1314 ._ReadOnly = .MetaData.isReadOnly()
1316 ._ReadOnly = .Connection.isReadOnly()
' Always True in Mysql ??
1318 Set .Document = oComponent
1319 .Title = oComponent.Title
1320 .URL = vDocContainer.URL
1321 .Location = oComponent.Location
1322 ReDim vDbContainers(
0 To
0)
1323 Set vDbContainers(
0) = vDbContainer
1324 TraceLog(TRACEANY, .Version, False)
1325 TraceLog(TRACEANY, UCase(cstThisSub)
& " " & .URL, False)
1328 Set oForms = oComponent.CurrentController.Model.DrawPage.Forms
1329 If oForms.Count
< 1 Then Goto Error_MainForm
1330 ReDim vDbContainers(
0 To oForms.Count -
1)
1331 For i =
0 To oForms.Count -
1
1332 vDbContainer = New DbContainer
' To make distinct entries !!
1333 sFormName = oForms.ElementNames(i)
1334 Set vDbContainer.Database = New Database
1335 Set vDbContainer.Database._This = vDbContainer.Database
1336 With vDbContainer.Database
1337 .FormName = sFormName
1338 vDbContainer.FormName = sFormName
1339 Set .Form = oForms.getByName(sFormName)
1340 Set .Connection = .Form.ActiveConnection
' Might be Nothing in Windows at AOO/LO startup (not met in Linux)
1341 If Not IsNull(.Connection) Then
1342 Set .MetaData = .Connection.MetaData
1344 ._ReadOnly = .Connection.isReadOnly()
1345 TraceLog(TRACEANY, .MetaData.getDatabaseProductName()
& " " & .MetaData.getDatabaseProductVersion, False)
1347 Set .Document = oComponent
1348 .Title = oComponent.Title
1349 .URL = .Form.DataSourceName
1350 ._DbConnect = DBCONNECTFORM
1351 Set vDbContainers(i) = vDbContainer
1352 vDbContainers(i).FormName = sFormName
1353 TraceLog(TRACEANY, UCase(cstThisSub)
& " " & .URL
& " Form=
" & vDbContainer.FormName, False)
1356 vDocContainer.DbConnect = DBCONNECTFORM
1359 vDocContainer.DbContainers() = vDbContainers()
1360 Set vCurrentDoc(iCurrent) = vDocContainer
1362 _A2B_.CurrentDoc = vCurrentDoc
1363 Set OpenConnection = vDbContainers(
0).Database
1367 Utils._ResetCalledSub(cstThisSub)
1370 TraceError(TRACEABORT, Err, cstThisSub, Erl)
1371 Set _A2B_.CurrentDoc = Array()
1374 TraceError(TRACEFATAL, ERRMAINFORM, Utils._CalledSub(), False, ,oComponent.Title)
1375 Set _A2B_.CurrentDoc = Array()
1378 TraceError(TRACEABORT, ERRDBNOTCONNECTED, Utils._CalledSub(),
0,
1)
1380 End Function
' OpenConnection V1.1
.0
1382 REM -----------------------------------------------------------------------------------------------------------------------
1383 Public Function OpenDatabase ( _
1384 ByVal Optional pvDatabaseURL As Variant _
1385 , ByVal Optional pvUser As Variant _
1386 , ByVal Optional pvPassword As Variant _
1387 , ByVal Optional pvReadOnly As Variant _
1390 ' Return a database object based on input arguments:
1391 ' Call template:
1392 ' Call OpenDatabase(
"... databaseURL ...
"[,
"",
"", True/False])
1393 ' pvDatabaseURL may be the name of a registered database or the URL of the targeted .odb file
1394 ' Might be called from any AOO/LibO application, independently from OpenConnection
1396 Dim odbDatabase As Variant, oBaseContext As Object, sDbNames() As String, oBaseSource As Object
1397 Dim i As Integer, bFound As Boolean
1398 Dim sDatabaseURL As String
1400 If IsEmpty(_A2B_) Then
' First use of Access2Base in current AOO/LibO session
1401 Call Application._RootInit()
1402 TraceLog(TRACEANY, Utils._GetProductName()
& " -
" & Application.ProductCode(), False)
1404 Set OpenDatabase = Nothing
1406 If _ErrorHandler() Then On Local Error Goto Error_Function
1407 Const cstThisSub =
"OpenDatabase
"
1408 Utils._SetCalledSub(cstThisSub)
1409 If Not Utils._CheckArgument(pvDatabaseURL,
1, vbString) Then Goto Exit_Function
1410 If pvDatabaseURL =
"" Then Call _TraceArguments()
1411 If IsMissing(pvUser) Then pvUser =
""
1412 If IsMissing(pvPassword) Then pvPassword =
""
1413 If Not Utils._CheckArgument(pvUser,
2, vbString) Then Goto Exit_Function
1414 If Not Utils._CheckArgument(pvPassword,
3, vbString) Then Goto Exit_Function
1415 If IsMissing(pvReadOnly) Then pvReadOnly = False
1416 If Not Utils._CheckArgument(pvReadOnly,
3, vbBoolean) Then Goto Exit_Function
1418 Set odbDatabase = New Database
1419 Set odbDatabase._This = odbDatabase
1420 odbDatabase._DbConnect = DBCONNECTANY
1422 Set oBaseContext = CreateUnoService(
"com.sun.star.sdb.DatabaseContext
")
1423 sDbNames() = oBaseContext.getElementNames()
1425 For i =
0 To UBound(sDbNames())
' Enumerate registered databases and check non case-sensitive equality
1426 If UCase(sDbNames(i)) = UCase(pvDatabaseURL) Then
1427 sDatabaseURL = sDbNames(i)
1428 Set oBaseSource = oBaseContext.getByName(sDatabaseURL)
1429 odbDatabase.Location = oBaseContext.getDatabaseLocation(sDbNames(i))
1435 sDatabaseURL = ConvertToURL(pvDatabaseURL)
1436 If UCase(Right(sDatabaseURL,
4))
<> ".ODB
" Then Goto Trace_Error
1437 If Not FileExists(sDatabaseURL) Then Goto Trace_Error
1438 Set oBaseSource = oBaseContext.getByName(sDatabaseURL)
1439 odbDatabase.Location = sDatabaseURL
1442 Set odbDatabase.Connection = oBaseSource.getConnection(pvUser, pvPassword)
1443 If Not IsNull(odbDatabase.Connection) Then
' Null when standalone and target db does not exist
1444 Set odbDatabase.MetaData = odbDatabase.Connection.MetaData
1445 odbDatabase._LoadMetadata()
1450 odbDatabase.URL = sDatabaseURL
1453 odbDatabase.Connection.isReadOnly = True
1454 odbDatabase._ReadOnly = True
1457 Set OpenDatabase = odbDatabase
1459 TraceLog(TRACEANY, odbDatabase.MetaData.getDatabaseProductName()
& " " & odbDatabase.MetaData.getDatabaseProductVersion, False)
1460 TraceLog(TRACEANY, UCase(cstThisSub)
& " " & odbDatabase.URL, False)
1464 Utils._ResetCalledSub(cstThisSub)
1467 TraceError(TRACEABORT, Err, cstThisSub, Erl)
1470 TraceError(TRACEABORT, ERRDBNOTCONNECTED, Utils._CalledSub(),
0,
1)
1472 End Function
' OpenDatabase V1.1
.0
1474 REM -----------------------------------------------------------------------------------------------------------------------
1475 Public Function ProductCode()
1476 If IsEmpty(_A2B_) Then Call Application._RootInit()
' First use of Access2Base in current AOO/LibO session
1477 ProductCode =
"Access2Base
" & _A2B_.VersionNumber
1478 End Function
' ProductCode V0.9
.1
1480 REM -----------------------------------------------------------------------------------------------------------------------
1481 Public Function setValue(Optional pvObject As Variant, ByVal Optional pvValue As Variant) As Boolean
1482 ' setValue also interprets shortcut strings !!
1483 Dim vItem As Variant, sProperty As String
1484 If IsMissing(pvObject) Or IsMissing(pvValue) Or IsEmpty(pvObject) Then Call _TraceArguments(
"setValue
")
1485 If VarType(pvObject) = vbString Then
1486 Utils._SetCalledSub(
"setValue
")
1487 Set vItem = getObject(pvObject)
1488 sProperty = Utils._FinalProperty(pvObject)
1489 If sProperty =
"" Then sProperty =
"Value
"
1490 setValue = vItem.setProperty(sProperty, pvValue)
1491 Utils._ResetCalledSub(
"setValue
")
1493 Set vItem = pvObject
1494 setValue = vItem.setProperty(
"Value
", pvValue)
1496 End Function
' setValue
1498 REM -----------------------------------------------------------------------------------------------------------------------
1499 Public Function SysCmd(Optional pvAction As Variant _
1500 , Optional pvText As Variant _
1501 , Optional pvValue As Variant _
1503 ' Manage progress meter in the status bar
1504 ' Other values supported by MSAccess are ignored
1506 If _ErrorHandler() Then On Local Error Goto Error_Function
1507 Const cstThisSub =
"SysCmd
"
1508 Utils._SetCalledSub(cstThisSub)
1511 Const cstMissing = -
1
1512 Const cstBarLength =
350
1513 If IsMissing(pvAction) Then Call _TraceArguments()
1514 If Not Utils._CheckArgument(pvAction,
1, Utils._AddNumeric(), Array( _
1516 , acSysCmdAccessVer _
1517 , acSysCmdClearHelpTopic _
1518 , acSysCmdClearStatus _
1519 , acSysCmdGetObjectState _
1520 , acSysCmdGetWorkgroupFile _
1522 , acSysCmdInitMeter _
1524 , acSysCmdRemoveMeter _
1526 , acSysCmdSetStatus _
1527 , acSysCmdUpdateMeter _
1528 )) Then Goto Exit_Function
1529 If IsMissing(pvValue) Then pvValue = cstMissing
1530 If Not Utils._CheckArgument(pvAction,
1, Utils._AddNumeric()) Then Goto Exit_Function
1531 Select Case pvAction
1532 Case acSysCmdInitMeter, acSysCmdUpdateMeter, acSysCmdSetStatus
1533 If IsMissing(pvText) Then Call _TraceArguments()
1534 If Not Utils._CheckArgument(pvText,
2, vbString) Then Goto Exit_Function
1537 If Not Utils._CheckArgument(pvValue,
3, Utils._AddNumeric()) Then Goto Exit_Function
1539 Dim vBar As Variant, iLen As Integer
1540 Set vBar = _A2B_.StatusBar
1541 Select Case pvAction
1542 Case acSysCmdAccessVer
1543 SysCmd = Application.Version()
1545 Case acSysCmdSetStatus
1546 If pvValue
<> cstMissing Then Goto Error_Arg
1549 If Not IsNull(vBar) Then vBar.start(Iif(iLen
>= cstBarLength, pvText, pvText
& Space(cstBarLength - iLen)),
0)
1550 Case acSysCmdClearStatus
1551 If pvValue
<> cstMissing Then Goto Error_Arg
1552 If Not IsNull(vBar) Then
1554 Set _A2B_.StatusBar = Nothing
1556 Case acSysCmdInitMeter
1557 If pvValue = cstMissing Then Call _TraceArguments()
1559 If Not IsNull(vBar) Then vBar.start(pvText, pvValue)
1560 Case acSysCmdUpdateMeter
1561 If pvValue = cstMissing Then Call _TraceArguments()
1562 If Not IsNull(vBar) Then
' Otherwise ignore !
1563 vBar.setValue(pvValue)
1564 If Len(pvText)
> 0 Then vBar.setText(pvText)
1566 Case acSysCmdRemoveMeter
1567 If Not IsNull(vBar) Then
1569 Set _A2B_.StatusBar = Nothing
1571 Case acSysCmdRuntime
1580 Utils._ResetCalledSub(cstThisSub)
1583 TraceError(TRACEABORT, Err, cstThisSub, Erl)
1586 TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(),
0,
1, Array(
3, pvValue))
1588 End Function
' SysCmd V0.9
.1
1590 REM -----------------------------------------------------------------------------------------------------------------------
1591 Public Function TempVars(ByVal Optional pvIndex As Variant) As Variant
1592 ' Return either a Collection or a TempVar object
1594 If _ErrorHandler() Then On Local Error Goto Error_Function
1595 Const cstThisSub =
"TempVars
"
1596 Utils._SetCalledSub(cstThisSub)
1598 Dim iMode As Integer, vTempVars As Variant, bFound As Boolean
1600 Const cstByIndex =
1
1603 If IsMissing(pvIndex) Then
1606 If Not Utils._CheckArgument(pvIndex,
1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
1607 If VarType(pvIndex) = vbString Then iMode = cstByName Else iMode = cstByIndex
1610 Set vTempVars = Nothing
1612 Case cstCount
' Build Collection object
1613 Set vTempVars = New Collect
1616 ._CollType = COLLTEMPVARS
1617 ._Count = _A2B_.TempVars.Count
1619 Case cstByIndex
' Build TempVar object
1620 If pvIndex
< 0 Or pvIndex
>= _A2B_.TempVars.Count Then Goto Trace_Error_Index
1621 Set vTempVars = _A2B_.TempVars.Item(pvIndex +
1)
' Builtin collections start at
1
1623 bFound = _A2B_.hasItem(COLLTEMPVARS, pvIndex)
1624 If Not bFound Then Goto Trace_NotFound
1625 vTempVars = _A2B_.TempVars.Item(UCase(pvIndex))
1628 Set TempVars = vTempVars
1631 Utils._ResetCalledSub(cstThisSub)
1634 TraceError(TRACEABORT, Err, cstThisSub, Erl)
1637 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(),
0,
1)
1638 Set vTempVars = Nothing
1641 TraceError(TRACEFATAL, ERROBJECTNOTFOUND, Utils._CalledSub(),
0, , Array(_GetLabel(
"TEMPVAR
"), pvIndex))
1643 End Function
' TempVars V1.2
.0
1645 REM -----------------------------------------------------------------------------------------------------------------------
1646 Public Function Version() As String
1647 Version = Utils._GetProductName()
1648 End Function
' Version V0.9
.1
1650 REM -----------------------------------------------------------------------------------------------------------------------
1651 REM --- PRIVATE FUNCTIONS ---
1652 REM -----------------------------------------------------------------------------------------------------------------------
1654 REM -----------------------------------------------------------------------------------------------------------------------
1655 Private Function _CollectNames(ByRef poCollection As Object, ByVal psPrefix As String) As Variant
1656 ' Return a
"\;
" separated list of hierarchical (prefixed with Prefix) and persistent names contained in Collection
1657 ' If one of those names refers to a folder, function is called recursively
1658 ' Result =
2 items array: (
0) list of hierarchical names
1659 ' (
1) list of persistent names
1661 Dim oObject As Object, vNamesList() As Variant, vPersistentList As Variant, i As Integer, sCollect(
0 To
1) As String
1662 Dim sName As String, sType As String, sPrefix As String
1663 Const cstFormType =
"application/vnd.oasis.opendocument.text
"
1664 Const cstSeparator =
"\;
"
1666 _CollectNames = sCollect()
1667 vPersistentList = Array()
1670 If .getCount =
0 Then Exit Function
1671 vNamesList = .getElementNames()
1672 ReDim vPersistentList(
0 To UBound(vNamesList))
1674 For i =
0 To UBound(vNamesList)
1675 sName = vNamesList(i)
1676 Set oObject = .getByName(sName)
1677 sType = oObject.getContentType()
1680 vNamesList(i) = psPrefix
& vNamesList(i)
1681 vPersistentList(i) = oObject.PersistentName
1682 Case
"" ' Folder
1683 sCollect = _CollectNames(oObject, psPrefix
& sName
& "/
")
1684 vNamesList(i) = sCollect(
0)
1685 vPersistentList(i) = sCollect(
1)
1692 Set oObject = Nothing
1693 sCollect(
0) = Join(vNamesList, cstSeparator)
1694 sCollect(
1) = Join(vPersistentList, cstSeparator)
1695 _CollectNames = sCollect()
1697 End Function
' _CollectNames V6.2
.0
1699 REM -----------------------------------------------------------------------------------------------------------------------
1700 Public Function _CountOpenForms(ByVal Optional piCountMax As Integer) As Variant
1701 ' Return # of active forms if no argument
1702 ' Return name of piCountMax-th open form if argument present
1704 Dim i As Integer, iCount As Integer, iAllCount As Integer, ofForm As Variant
1705 iAllCount = AllForms._Count
1707 If iAllCount
> 0 Then
1708 For i =
0 To iAllCount -
1
1709 Set ofForm = Application.AllForms(i)
1710 If ofForm._IsLoaded Then iCount = iCount +
1
1711 If Not IsMissing(piCountMax) Then
1712 If iCount = piCountMax +
1 Then
1713 _CountOpenForms = ofForm
' OO3.2 aborts when Set verb present ?!?
1720 If IsMissing(piCountMax) Then _CountOpenForms = iCount
1722 End Function
' CountOpenForms V1.1
.0
1724 REM -----------------------------------------------------------------------------------------------------------------------
1725 Public Function _CurrentDb(ByVal Optional piDocEntry As Integer, ByVal Optional piDbEntry As Integer) As Variant
1726 REM Without arguments same as CurrentDb() except that it generates an error if database not connected (internal use)
1727 REM With
2 arguments return the corresponding entry in Root
1729 Dim oCurrentDb As Object
1730 If IsEmpty(_A2B_) Then GoTo Trace_Error
1731 If IsMissing(piDocEntry) Then Set oCurrentDb = Application.CurrentDb() _
1732 Else Set oCurrentDb = _A2B_._CurrentDb(piDocEntry, piDbEntry)
1733 If IsNull(oCurrentDb) Then Goto Trace_Error Else Set _CurrentDb = oCurrentDb
1738 TraceError(TRACEABORT, ERRDBNOTCONNECTED, Utils._CalledSub(),
0,
1)
1740 End Function
' _CurrentDb V1.1
.0
1742 REM -----------------------------------------------------------------------------------------------------------------------
1743 Private Function _GetAllHierarchicalNames() As Variant
1744 ' Return the full hierarchical names list of a database document
1745 ' Get it from the vFormNamesList buffer if the latter is not empty
1747 Dim vNamesList As Variant, iCurrentDoc As Integer, vCurrentDoc As Variant
1748 Dim oForms As Object
1749 Const cstSeparator =
"\;
"
1751 _GetAllHierarchicalNames = Array()
1753 ' Load complete list of names when Base document
1754 iCurrentDoc = _A2B_.CurrentDocIndex()
1755 If iCurrentDoc
>=
0 Then vCurrentDoc = _A2B_.CurrentDocument(iCurrentDoc) Else Exit Function
1756 If vCurrentDoc.DbConnect = DBCONNECTBASE Then
1757 If IsEmpty(vFormNamesList) Then
1758 Set oForms = vCurrentDoc.Document.getFormDocuments()
1759 vFormNamesList = _CollectNames(oForms,
"")
1761 vNamesList = Split(vFormNamesList(
0), cstSeparator)
1766 _GetAllHierarchicalNames = vNamesList
1767 Set oForms = Nothing
1769 End Function
' _GetAllHierarchicalNames V
6.2.0
1771 REM -----------------------------------------------------------------------------------------------------------------------
1772 Private Function _GetHierarchicalName(ByVal psPersistent As String) As String
1773 ' Return the full hierarchical name from the persistent name of a form/report
1775 Dim vPersistentList As Variant, vNamesList As Variant, i As Integer
1776 Const cstSeparator =
"\;
"
1778 _GetHierarchicalName =
""
1780 ' Load complete list of names when Base document
1781 vNamesList = _GetAllHierarchicalNames()
1782 If UBound(vNamesList)
< 0 Then Exit Function
1783 vPersistentList = Split(vFormNamesList(
1), cstSeparator)
1785 ' Search in list
1786 For i =
0 To UBound(vPersistentList)
1787 If vPersistentList(i) = psPersistent Then
1788 _GetHierarchicalName = vNamesList(i)
1793 End Function
' _GetHierarchicalName V
6.2.0
1795 REM -----------------------------------------------------------------------------------------------------------------------
1796 Private Function _NewBar() As Object
1797 ' Close current status bar, if any, and initialize new one
1799 Dim vBar As Variant, vWindow As Variant, vController As Object
1800 On Local Error Resume Next
1801 Set _NewBar = Nothing
1803 Set vBar = _A2B_.StatusBar
1804 If Not IsNull(vBar) Then
1805 If Utils._hasUNOMethod(vBar,
"end
") Then vBar.end()
1806 Set _A2B_.StatusBar = Nothing
1810 Set vWindow = _SelectWindow()
1811 If IsNull(vWindow.Frame) Then Exit Function
1812 Select Case vWindow.WindowType
1813 Case acForm, acReport, acBasicIDE, acDocument
' Not found how to make it work for acDatabaseWindow
1817 If Utils._hasUNOMethod(vWindow.Frame,
"getCurrentController
") Then
1818 Set vController = vWindow.Frame.getCurrentController()
1819 ElseIf Utils._hasUNOMethod(vWindow.Frame,
"getController
") Then
1820 Set vController = vWindow.Frame.getController()
1823 If Utils._hasUNOMethod(vController,
"getStatusIndicator
") Then vBar = vController.getStatusIndicator()
1824 Set _A2B_.StatusBar = vBar
1828 End Function
' _NewBar V1.1
.0
1830 REM -----------------------------------------------------------------------------------------------------------------------
1831 Private Function _NewCommandBar(psModule As String _
1832 , psToolbarName As String _
1833 , psToolbarFullName As String _
1834 , piBuiltin As Integer _
1837 Dim oObject As Object
1838 Set oObject = New CommandBar
1841 ._Type = OBJCOMMANDBAR
1842 ._Name = psToolbarName
1843 ._ResourceURL = psToolbarFullName
1845 ._BarBuiltin = piBuiltin
1846 Select Case UCase(Split(psToolbarFullName,
"/
")(
1))
1847 Case
"MENUBAR
" : ._BarType = msoBarTypeMenuBar
1848 Case
"STATUSBAR
" : ._BarType = msoBarTypeStatusBar
1849 Case
"TOOLBAR
" : ._BarType = msoBarTypeNormal
1850 Case
"POPUP
" : ._BarType = msoBarTypePopup
1851 Case
"FLOATER
" : ._BarType = msoBarTypeFloater
1852 Case Else : ._BarType = -
1
1855 Set _NewCommandBar = oObject
1858 End Function
' NewCommandBar V1.3
.0
1860 REM -----------------------------------------------------------------------------------------------------------------------
1861 Public Sub _RootInit(Optional ByVal pbForce As Boolean)
1862 ' Initialize _A2B_ global variable. Reinit forced if pbForce = True
1864 If IsMissing(pbForce) Then pbForce = False
1865 If IsEmpty(_A2B_) Or pbForce Then _A2B_ = New Root_
1867 End Sub
' _RootInit V1.1
.0