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">REM =======================================================================================================================
4 REM === The Access2Base library is a part of the LibreOffice project. ===
5 REM === Full documentation is available on http://www.access2base.com ===
6 REM =======================================================================================================================
10 REM -----------------------------------------------------------------------------------------------------------------------
11 Global Const TRACEDEBUG =
"DEBUG
" ' To report values of variables
12 Global Const TRACEINFO =
"INFO
" ' To report any event
13 Global Const TRACEWARNING =
"WARNING
" ' To report some abnormal event
14 Global Const TRACEERRORS =
"ERROR
" ' To report user errors - Default value
15 Global Const TRACEFATAL =
"FATAL
" ' To report programmer errors - f.i. Wrong argument
16 Global Const TRACEABORT =
"ABORT
" ' To report Access2Base internal errors
17 Global Const TRACEANY =
"===
>" ' Always reported
18 ' ERRORs, FATALs and ABORTs are also displayed in a MsgBox (except on specific request)
19 ' FATALs and ABORTs interrupt the program execution
21 Global Const ERRINIT =
1500
22 Global Const ERRDBNOTCONNECTED =
1501
23 Global Const ERRMISSINGARGUMENTS =
1502
24 Global Const ERRWRONGARGUMENT =
1503
25 Global Const ERRMAINFORM =
1504
26 Global Const ERRMETHOD =
1505
27 Global Const ERRFILEACCESS =
1506
28 Global Const ERRFORMNOTIDENTIFIED =
1507
29 Global Const ERRFORMNOTFOUND =
1508
30 Global Const ERRFORMNOTOPEN =
1509
31 Global Const ERRDFUNCTION =
1510
32 Global Const ERROPENFORM =
1511
33 Global Const ERRPROPERTY =
1512
34 Global Const ERRPROPERTYVALUE =
1513
35 Global Const ERRINDEXVALUE =
1514
36 Global Const ERRCOLLECTION =
1515
37 Global Const ERRPROPERTYNOTARRAY =
1516
38 Global Const ERRCONTROLNOTFOUND =
1517
39 Global Const ERRNOACTIVEFORM =
1518
40 Global Const ERRDATABASEFORM =
1519
41 Global Const ERRFOCUSINGRID =
1520
42 Global Const ERRNOGRIDINFORM =
1521
43 Global Const ERRFINDRECORD =
1522
44 Global Const ERRSQLSTATEMENT =
1523
45 Global Const ERROBJECTNOTFOUND =
1524
46 Global Const ERROPENOBJECT =
1525
47 Global Const ERRCLOSEOBJECT =
1526
48 Global Const ERRMETHOD =
1527
49 Global Const ERRACTION =
1528
50 Global Const ERRSENDMAIL =
1529
51 Global Const ERRFORMYETOPEN =
1530
52 Global Const ERRPROPERTYINIT =
1531
53 Global Const ERRFILENOTCREATED =
1532
54 Global Const ERRDIALOGNOTFOUND =
1533
55 Global Const ERRDIALOGUNDEFINED =
1534
56 Global Const ERRDIALOGSTARTED =
1535
57 Global Const ERRDIALOGNOTSTARTED =
1536
58 Global Const ERRRECORDSETNODATA =
1537
59 Global Const ERRRECORDSETCLOSED =
1538
60 Global Const ERRRECORDSETRANGE =
1539
61 Global Const ERRRECORDSETFORWARD =
1540
62 Global Const ERRFIELDNULL =
1541
63 Global Const ERROVERFLOW =
1542
64 Global Const ERRNOTACTIONQUERY =
1543
65 Global Const ERRNOTUPDATABLE =
1544
66 Global Const ERRUPDATESEQUENCE =
1545
67 Global Const ERRNOTNULLABLE =
1546
68 Global Const ERRROWDELETED =
1547
69 Global Const ERRRECORDSETCLONE =
1548
70 Global Const ERRQUERYDEFDELETED =
1549
71 Global Const ERRTABLEDEFDELETED =
1550
72 Global Const ERRTABLECREATION =
1551
73 Global Const ERRFIELDCREATION =
1552
74 Global Const ERRSUBFORMNOTFOUND =
1553
75 Global Const ERRWINDOW =
1554
76 Global Const ERRCOMPATIBILITY =
1555
77 Global Const ERRPRECISION =
1556
78 Global Const ERRMODULENOTFOUND =
1557
79 Global Const ERRPROCEDURENOTFOUND =
1558
81 REM -----------------------------------------------------------------------------------------------------------------------
82 Global Const DBCONNECTBASE =
1 ' Connection from Base document (OpenConnection)
83 Global Const DBCONNECTFORM =
2 ' Connection from a database-aware form (OpenConnection)
84 Global Const DBCONNECTANY =
3 ' Connection from any document for data access only (OpenDatabase)
86 REM -----------------------------------------------------------------------------------------------------------------------
87 Global Const DBMS_UNKNOWN =
0
88 Global Const DBMS_HSQLDB1 =
1
89 Global Const DBMS_HSQLDB2 =
2
90 Global Const DBMS_FIREBIRD =
3
91 Global Const DBMS_MSACCESS2003 =
4
92 Global Const DBMS_MSACCESS2007 =
5
93 Global Const DBMS_MYSQL =
6
94 Global Const DBMS_POSTGRES =
7
95 Global Const DBMS_SQLITE =
8
97 REM -----------------------------------------------------------------------------------------------------------------------
98 Global Const COLLALLDIALOGS =
"ALLDIALOGS
"
99 Global Const COLLALLFORMS =
"ALLFORMS
"
100 Global Const COLLALLMODULES =
"ALLMODULES
"
101 Global Const COLLCOMMANDBARS =
"COMMANDBARS
"
102 Global Const COLLCOMMANDBARCONTROLS =
"COMMANDBARCONTROLS
"
103 Global Const COLLCONTROLS =
"CONTROLS
"
104 Global Const COLLFORMS =
"FORMS
"
105 Global Const COLLFIELDS =
"FIELDS
"
106 Global Const COLLPROPERTIES =
"PROPERTIES
"
107 Global Const COLLQUERYDEFS =
"QUERYDEFS
"
108 Global Const COLLRECORDSETS =
"RECORDSETS
"
109 Global Const COLLTABLEDEFS =
"TABLEDEFS
"
110 Global Const COLLTEMPVARS =
"TEMPVARS
"
112 REM -----------------------------------------------------------------------------------------------------------------------
113 Global Const OBJAPPLICATION =
"APPLICATION
"
114 Global Const OBJCOLLECTION =
"COLLECTION
"
115 Global Const OBJCOMMANDBAR =
"COMMANDBAR
"
116 Global Const OBJCOMMANDBARCONTROL =
"COMMANDBARCONTROL
"
117 Global Const OBJCONTROL =
"CONTROL
"
118 Global Const OBJDATABASE =
"DATABASE
"
119 Global Const OBJDIALOG =
"DIALOG
"
120 Global Const OBJEVENT =
"EVENT
"
121 Global Const OBJFIELD =
"FIELD
"
122 Global Const OBJFORM =
"FORM
"
123 Global Const OBJMODULE =
"MODULE
"
124 Global Const OBJOPTIONGROUP =
"OPTIONGROUP
"
125 Global Const OBJPROPERTY =
"PROPERTY
"
126 Global Const OBJQUERYDEF =
"QUERYDEF
"
127 Global Const OBJRECORDSET =
"RECORDSET
"
128 Global Const OBJSUBFORM =
"SUBFORM
"
129 Global Const OBJTABLEDEF =
"TABLEDEF
"
130 Global Const OBJTEMPVAR =
"TEMPVAR
"
132 REM -----------------------------------------------------------------------------------------------------------------------
133 Global Const CTLCONTROL =
"CONTROL
" ' ClassId
134 Global Const CTLCHECKBOX =
"CHECKBOX
" ' 5
135 Global Const CTLCOMBOBOX =
"COMBOBOX
" ' 7
136 Global Const CTLCOMMANDBUTTON =
"COMMANDBUTTON
" ' 2
137 Global Const CTLCURRENCYFIELD =
"CURRENCYFIELD
" ' 18
138 Global Const CTLDATEFIELD =
"DATEFIELD
" ' 15
139 Global Const CTLFILECONTROL =
"FILECONTROL
" ' 12
140 Global Const CTLFIXEDTEXT =
"FIXEDTEXT
" ' 10
141 Global Const CTLGRIDCONTROL =
"GRIDCONTROL
" ' 11
142 Global Const CTLGROUPBOX =
"GROUPBOX
" ' 8
143 Global Const CTLHIDDENCONTROL =
"HIDDENCONTROL
" ' 13
144 Global Const CTLIMAGEBUTTON =
"IMAGEBUTTON
" ' 4
145 Global Const CTLIMAGECONTROL =
"IMAGECONTROL
" ' 14
146 Global Const CTLLISTBOX =
"LISTBOX
" ' 6
147 Global Const CTLNAVIGATIONBAR =
"NAVIGATIONBAR
" ' 22
148 Global Const CTLNUMERICFIELD =
"NUMERICFIELD
" ' 17
149 Global Const CTLPATTERNFIELD =
"PATTERNFIELD
" ' 19
150 Global Const CTLRADIOBUTTON =
"RADIOBUTTON
" ' 3
151 Global Const CTLSCROLLBAR =
"SCROLLBAR
" ' 20
152 Global Const CTLSPINBUTTON =
"SPINBUTTON
" ' 21
153 Global Const CTLTEXTFIELD =
"TEXTFIELD
" ' 9
154 Global Const CTLTIMEFIELD =
"TIMEFIELD
" ' 16
155 REM -----------------------------------------------------------------------------------------------------------------------
156 Global Const CTLFORMATTEDFIELD =
"FORMATTEDFIELD
" ' 9 (idem TextField)
157 Global Const CTLFIXEDLINE =
"FIXEDLINE
" ' 24 (forced)
158 Global Const CTLPROGRESSBAR =
"PROGRESSBAR
" ' 23 (forced)
159 Global Const CTLSUBFORM =
"SUBFORMCONTROL
" ' None
160 REM -----------------------------------------------------------------------------------------------------------------------
161 Global Const CTLPARENTISFORM =
"FORM
"
162 Global Const CTLPARENTISDIALOG =
"DIALOG
"
163 Global Const CTLPARENTISSUBFORM =
"SUBFORM
"
164 Global Const CTLPARENTISGRID =
"GRID
"
165 Global Const CTLPARENTISGROUP =
"OPTIONGROUP
"
167 REM -----------------------------------------------------------------------------------------------------------------------
168 Global Const MODDOCUMENT =
"DOCUMENT
"
169 Global Const MODGLOBAL =
"GLOBAL
"
171 REM -----------------------------------------------------------------------------------------------------------------------
173 Document As Object
' com.sun.star.comp.dba.ODatabaseDocument or SwXTextDocument or ScModelObj
175 DbConnect As Integer
' DBCONNECTxxx constants
177 DbContainers() As Variant
' One entry by (data-aware) form
181 FormName As String
' name of data-aware form
182 Database As Object
' Database type
185 REM -----------------------------------------------------------------------------------------------------------------------
186 Public Function AllDialogs(ByVal Optional pvIndex As Variant) As Variant
187 ' Return either a Collection or a Dialog object
188 ' The dialogs are selected only if library is loaded
190 If _ErrorHandler() Then On Local Error Goto Error_Function
191 Const cstThisSub =
"AllDialogs
"
192 Utils._SetCalledSub(cstThisSub)
194 Dim iMode As Integer, vDialogs() As Variant, i As Integer, j As Integer, iCount As Integer
195 Dim oMacLibraries As Object, vAllDialogs As Variant, oLibrary As Object, vNames() As Variant, bFound As Boolean
196 Dim oLibDialog As Object, sLibrary As String, oDocLibraries As Object, bLocalStorage As Boolean
197 Dim vLibraries() As Variant, vMacLibraries() As Variant, vDocLibraries() As Variant, oDocMacLib As Object
198 Dim vCurrentDocument As Variant
202 Const cstSepar =
"!
"
204 If IsMissing(pvIndex) Then
207 If Not Utils._CheckArgument(pvIndex,
1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
208 If VarType(pvIndex) = vbString Then iMode = cstByName Else iMode = cstByIndex
211 Set vAllDialogs = Nothing
213 Set vCurrentDocument = _A2B_.CurrentDocument
214 If IsNull(vCurrentDocument) Then
215 Set oDocLibraries = Nothing
216 vDocLibraries = Array()
218 Set oDocLibraries = _A2B_.CurrentDocument.Document.DialogLibraries
' ThisComponent.DialogLibraries
219 vDocLibraries = oDocLibraries.getElementNames()
221 Set oMacLibraries = DialogLibraries
222 vMacLibraries = oMacLibraries.getElementNames()
223 'Remove Access2Base from the list
224 If _A2B_.ExcludeA2B Then
225 For i =
0 To UBound(vMacLibraries)
226 If Left(vMacLibraries(i),
11) =
"Access2Base
" Then vMacLibraries(i) =
""
229 vMacLibraries = Utils._TrimArray(vMacLibraries)
231 If UBound(vDocLibraries) + UBound(vMacLibraries)
< 0 Then
' No library
232 Set vAllDialogs = New Collect
233 vAllDialogs._CollType = COLLALLDIALOGS
234 vAllDialogs._ParentType = OBJAPPLICATION
235 vAllDialogs._ParentName =
""
236 vAllDialogs._Count =
0
242 For i =
0 To UBound(vDocLibraries) + UBound(vMacLibraries) +
1
244 If i
<= UBound(vDocLibraries) Then
245 sLibrary = vDocLibraries(i)
247 Set oDocMacLib = oDocLibraries
248 ' Sometimes library not loaded as should ??
249 If Not oDocMacLib.IsLibraryLoaded(sLibrary) Then oDocMacLib.loadLibrary(sLibrary)
251 sLibrary = vMacLibraries(i - UBound(vDocLibraries) -
1)
252 bLocalStorage = False
253 Set oDocMacLib = oMacLibraries
255 If oDocMacLib.IsLibraryLoaded(sLibrary) Then
256 Set oLibrary = oDocMacLib.getByName(sLibrary)
257 If oLibrary.hasElements() Then
258 vDialogs = oLibrary.getElementNames()
261 iCount = iCount + UBound(vDialogs) +
1
262 Case cstByIndex, cstByName
263 For j =
0 To UBound(vDialogs)
264 If iMode = cstByIndex Then
265 If pvIndex = iCount Then bFound = True
268 If UCase(pvIndex) = UCase(vDialogs(j)) Then bFound = True
271 Set oLibDialog = oLibrary.getByName(vDialogs(j))
' Create Dialog object
278 If bFound Then Exit For
281 If iMode = cstCount Then
282 Set vAllDialogs = New Collect
283 vAllDialogs._CollType = COLLALLDIALOGS
284 vAllDialogs._ParentType = OBJAPPLICATION
285 vAllDialogs._ParentName =
""
286 vAllDialogs._Count = iCount
289 If iMode = cstByIndex Then Goto Trace_Error_Index Else Goto Trace_Not_Found
291 Set vAllDialogs = New Dialog
294 ._Shortcut =
"Dialogs!
" & vDialogs(j)
295 Set ._Dialog = oLibDialog
297 ._Storage = Iif(bLocalStorage,
"DOCUMENT
",
"GLOBAL
")
302 Set AllDialogs = vAllDialogs
303 Utils._ResetCalledSub(cstThisSub)
306 TraceError(TRACEFATAL, ERRDIALOGNOTFOUND, Utils._CalledSub(),
0, , pvIndex)
309 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(),
0,
1)
310 Set vDialogs = Nothing
313 TraceError(TRACEABORT, Err, cstThisSub, Erl)
314 Set vDialogs = Nothing
316 End Function
' AllDialogs V0.9
.5
318 REM -----------------------------------------------------------------------------------------------------------------------
319 Public Function AllForms(ByVal Optional pvIndex As Variant) As Variant
320 ' Return an object of type Form indicated by either its index (integer) or its name (NOT CASE-SENSITIVE string)
321 ' Easiest use for standalone forms: AllForms(
0)
322 ' If no argument, return a Collection type
324 If _ErrorHandler() Then On Local Error Goto Error_Function
325 Const cstThisSub =
"AllForms
"
326 Utils._SetCalledSub(cstThisSub)
327 Dim iIndex As Integer, vAllForms As Variant
328 Set vAllForms = Nothing
330 If Not IsMissing(pvIndex) Then
331 If Not Utils._CheckArgument(pvIndex,
1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
332 Select Case VarType(pvIndex)
335 Case vbInteger, vbLong, vbSingle, vbDouble, vbCurrency, vbBigint, vbDecimal
340 Dim iCurrentDoc As Integer, vCurrentDoc As Variant, oForms As Variant, oCounter As Variant, oFormsCollection As Object
341 iCurrentDoc = _A2B_.CurrentDocIndex()
342 If iCurrentDoc
>=
0 Then
343 vCurrentDoc = _A2B_.CurrentDocument(iCurrentDoc)
347 If vCurrentDoc.DbConnect = DBCONNECTBASE Then Set oForms = vCurrentDoc.Document.getFormDocuments()
348 ' Process when NO ARGUMENT
349 If IsMissing(pvIndex) Then
' No argument
350 Set oCounter = New Collect
351 oCounter._CollType = COLLALLFORMS
352 oCounter._ParentType = OBJAPPLICATION
353 oCounter._ParentName =
""
354 If vCurrentDoc.DbConnect = DBCONNECTFORM Then oCounter._Count = UBound(vCurrentDoc.DbContainers) +
1 Else oCounter._Count = oForms.getCount()
355 Set vAllForms = oCounter
359 ' Process when ARGUMENT = STRING or INDEX =
> Initialize form object
361 Set ofForm = New Form
362 Dim sAllForms As Variant, i As Integer, vName As Variant, oDatabase As Object, bFound As Boolean
363 Select Case vCurrentDoc.DbConnect
365 sAllForms() = oForms.getElementNames()
368 If iIndex= -
1 Then
' String argument
369 vName = Utils._InList(Utils._Trim(pvIndex), sAllForms, True)
' hasByName not used because case sensitive
370 If vName = False Then Goto Trace_Not_Found
371 ofForm._Initialize(vName)
373 If iIndex +
1 > oForms.getCount() Or iIndex
< 0 Then Goto Trace_Error_Index
' Numeric argument OK but value nonsense
374 ofForm._Initialize(sAllForms(iIndex))
380 For i =
0 To UBound(vCurrentDoc.DbContainers)
381 Set oDatabase = vCurrentDoc.DbContainers(i).Database
382 If UCase(Utils._Trim(pvIndex)) = UCase(oDatabase.FormName) Then
388 If Not bFound Then Goto Trace_Not_Found
389 ElseIf iIndex
< 0 Or iIndex
> UBound(vCurrentDoc.DbContainers) Then
390 Goto Trace_Error_Index
392 ofForm._DbEntry = iIndex
393 Set oDatabase = vCurrentDoc.DbContainers(iIndex).Database
396 vName = oDatabase.FormName
397 ofForm._DocEntry = iCurrentDoc
398 ofForm._Initialize(vName)
401 Set vAllForms = ofForm
404 Set AllForms = vAllForms
405 Utils._ResetCalledSub(cstThisSub)
408 TraceError(TRACEFATAL, ERRFORMNOTFOUND, Utils._CalledSub(),
0, , pvIndex)
411 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(),
0,
1)
412 Set vAllForms = Nothing
415 TraceError(TRACEABORT, Err, cstThisSub, Erl)
416 Set vAllForms = Nothing
418 End Function
' AllForms V0.9
.0
420 REM -----------------------------------------------------------------------------------------------------------------------
421 Public Function AllModules(ByVal Optional pvIndex As Variant, ByVal Optional pbAllModules As Boolean) As Variant
422 ' Return either a Collection or a Module object
423 ' The modules are selected only if library is loaded
424 ' (UNPUBLISHED) pbAllModules = False collects only the modules located in the currently open document
426 If _ErrorHandler() Then On Local Error Goto Error_Function
427 Const cstThisSub =
"AllModules
"
428 Utils._SetCalledSub(cstThisSub)
430 Dim iMode As Integer, vModules() As Variant, i As Integer, j As Integer, iCount As Integer
431 Dim oMacLibraries As Object, vAllModules As Variant, oLibrary As Object, vNames() As Variant, bFound As Boolean
432 Dim sScript As String, sLibrary As String, oDocLibraries As Object, sStorage As String
433 Dim vLibraries() As Variant, vMacLibraries() As Variant, vDocLibraries() As Variant, oDocMacLib As Object
434 Const cstCount =
0, cstByIndex =
1, cstByName =
2
435 Const cstDot =
".
"
437 If IsMissing(pvIndex) Then
440 If Not Utils._CheckArgument(pvIndex,
1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
441 If VarType(pvIndex) = vbString Then
443 ' Determine full name STORAGE.LIBRARY.MODULE
444 vNames = Split(pvIndex, cstDot)
445 If UBound(vNames) =
2 Then
446 ElseIf UBound(vNames) =
1 Then
447 pvIndex = MODDOCUMENT
& cstDot
& pvIndex
448 ElseIf UBound(vNames) =
0 Then
449 pvIndex = MODDOCUMENT
& cstDot
& "STANDARD
" & cstDot
& pvIndex
458 If IsMissing(pbAllModules) Then pbAllModules = True
459 If Not Utils._CheckArgument(pbAllModules,
2, vbBoolean) Then Goto Exit_Function
461 Set vAllModules = Nothing
463 Set oDocLibraries = _A2B_.CurrentDocument.Document.BasicLibraries
' ThisComponent.BasicLibraries
464 vDocLibraries = oDocLibraries.getElementNames()
466 Set oMacLibraries = GlobalScope.BasicLibraries
467 vMacLibraries = oMacLibraries.getElementNames()
468 'Remove Access2Base from the list
469 If _A2B_.ExcludeA2B Then
470 For i =
0 To UBound(vMacLibraries)
471 If Left(vMacLibraries(i),
11) =
"Access2Base
" Then vMacLibraries(i) =
""
474 vMacLibraries = Utils._TrimArray(vMacLibraries)
477 If UBound(vDocLibraries) + UBound(vMacLibraries)
< 0 Then
' No library
478 Set vAllModules = New Collect
479 vAllModules._CollType = COLLALLMODULES
480 vAllModules._ParentType = OBJAPPLICATION
481 vAllModules._ParentName =
""
482 vAllModules._Count =
0
487 For i =
0 To UBound(vDocLibraries) + UBound(vMacLibraries) +
1
489 If i
<= UBound(vDocLibraries) Then
490 sLibrary = vDocLibraries(i)
491 sStorage = MODDOCUMENT
492 Set oDocMacLib = oDocLibraries
493 ' Sometimes library not loaded as should ??
494 If Not oDocMacLib.IsLibraryLoaded(sLibrary) Then oDocMacLib.loadLibrary(sLibrary)
496 sLibrary = vMacLibraries(i - UBound(vDocLibraries) -
1)
498 Set oDocMacLib = oMacLibraries
500 If oDocMacLib.IsLibraryLoaded(sLibrary) Then
501 Set oLibrary = oDocMacLib.getByName(sLibrary)
502 If oLibrary.hasElements() Then
503 vModules = oLibrary.getElementNames()
506 iCount = iCount + UBound(vModules) +
1
507 Case cstByIndex, cstByName
508 For j =
0 To UBound(vModules)
509 If iMode = cstByIndex Then
510 If pvIndex = iCount Then bFound = True
513 If UCase(pvIndex) = UCase(sStorage
& cstDot
& sLibrary
& cstDot
& vModules(j)) Then bFound = True
516 sScript = oLibrary.getByName(vModules(j))
' Initiate Module object
524 If bFound Then Exit For
527 If iMode = cstCount Then
528 Set vAllModules = New Collect
529 vAllModules._CollType = COLLALLMODULES
530 vAllModules._ParentType = OBJAPPLICATION
531 vAllModules._ParentName =
""
532 vAllModules._Count = iCount
535 If iMode = cstByIndex Then Goto Trace_Error_Index Else Goto Trace_Not_Found
537 Set vAllModules = New Module
538 vAllModules._Name = vModules(j)
539 vAllModules._LibraryName = sLibrary
540 Set vAllModules._Library = oLibrary
541 vAllModules._Storage = sStorage
542 vAllModules._Script = sScript
543 vAllModules._Initialize()
547 Set AllModules = vAllModules
548 Utils._ResetCalledSub(cstThisSub)
551 TraceError(TRACEFATAL, ERRMODULENOTFOUND, Utils._CalledSub(),
0, , pvIndex)
554 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(),
0,
1)
555 Set vModules = Nothing
558 TraceError(TRACEABORT, Err, cstThisSub, Erl)
559 Set vModules = Nothing
561 End Function
' AllModules V1.7
.0
563 REM -----------------------------------------------------------------------------------------------------------------------
564 Public Sub CloseConnection ()
566 ' Close all connections established by current document to free memory.
567 ' - if Base document =
> close the one concerned database connection
568 ' - if non-Base documents =
> close the connections of each individual standalone form
570 If IsEmpty(_A2B_) Then Goto Exit_Sub
572 Const cstThisSub =
"CloseConnection
"
573 Utils._SetCalledSub(cstThisSub)
575 Call _A2B_.CloseConnection()
578 Utils._ResetCalledSub(cstThisSub)
580 End Sub
' CloseConnection V1.2
.0
582 REM -----------------------------------------------------------------------------------------------------------------------
583 Public Function CommandBars(Optional ByVal pvIndex As Variant, Optional ByRef poWindow As Object) As Variant
584 ' Return an object of type CommandBar indicated by its index or its name (CASE-INSENSITIVE string)
585 ' If no pvIndex argument, return a Collection type
586 ' (Unpublished) With poWindow, force the frame in which toolbars are detected
588 If _ErrorHandler() Then On Local Error Goto Error_Function
589 Const cstThisSub =
"CommandBars
"
590 Utils._SetCalledSub(cstThisSub)
592 Dim iObjectsCount As Integer, sObjectName As String, oObject As Object
593 Dim oWindow As Object, iWindowType As Integer
594 Dim i As Integer, j As Integer, k As Integer, bFound As Boolean
595 Dim sSupportedModules() As Variant, vModules() As Variant, oModuleUI As Object
596 Dim oToolbar As Object, sToolbarName As String, vUIElements() As Variant, sToolbarFullName As String, iBuiltin As Integer
598 Const cstCustom =
"CUSTOM
"
600 Set oObject = Nothing
601 If Not IsMissing(pvIndex) Then
602 If Not Utils._CheckArgument(pvIndex,
1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
608 If IsMissing(poWindow) Then Set oWindow = _SelectWindow() Else Set oWindow = poWindow
609 If IsNull(oWindow.Frame) Then Goto Trace_WindowError
611 ' List of
21 modules
612 vModules = CreateUnoService(
"com.sun.star.frame.ModuleManager
").getElementNames()
614 iWindowType = oWindow.WindowType
615 Select Case iWindowType
' Supported window types only
617 sSupportedModules = Array(
"com.sun.star.sdb.FormDesign
" )
619 sSupportedModules = Array(
"com.sun.star.script.BasicIDE
" )
620 Case acDatabaseWindow
621 sSupportedModules = Array(
"com.sun.star.sdb.OfficeDatabaseDocument
" )
623 sSupportedModules = Array(
"com.sun.star.sdb.TextReportDesign
" )
625 Select Case oWindow.DocumentType
626 Case docCalc : sSupportedModules = Array(
"com.sun.star.sheet.SpreadsheetDocument
" )
627 Case docWriter : sSupportedModules = Array(
"com.sun.star.text.TextDocument
" )
628 Case docImpress : sSupportedModules = Array(
"com.sun.star.presentation.PresentationDocument
" )
629 Case docDraw : sSupportedModules = Array(
"com.sun.star.drawing.DrawingDocument
" )
630 Case docMath : sSupportedModules = Array(
"com.sun.star.formula.FormulaProperties
" )
631 Case Else : sSupportedModules = Array()
633 Case acTable, acQuery
634 sSupportedModules = Array(
"com.sun.star.sdb.DataSourceBrowser
" _
635 ,
"com.sun.star.sdb.TableDataView
" _
638 sSupportedModules = Array(
"com.sun.star.sdb.RelationDesign
" )
640 sSupportedModules = Array(
"com.sun.star.frame.StartModule
" )
642 sSupportedModules = Array()
645 ' Find all standard and custom toolbars stored in LibO/AOO Base
646 Set oModuleUI = CreateUnoService(
"com.sun.star.ui.ModuleUIConfigurationManagerSupplier
")
647 For k =
0 To UBound(vModules)
648 For j =
0 To UBound(sSupportedModules)
649 iBuiltin =
1 ' Default = builtin
650 If vModules(k) = sSupportedModules(j) Then
' Supported modules only
651 Set oToolbar = oModuleUI.getUIConfigurationManager(vModules(k))
652 vUIElements() = oToolbar.getUIElementsInfo(
0)
653 For i =
0 To UBound(vUIElements)
654 sToolbarFullName = _GetPropertyValue(vUIElements(i),
"ResourceURL
")
655 sToolbarName = Split(sToolbarFullName,
"/
")(
2)
656 If _IsLeft(UCase(sToolbarName), UCase(cstCustom)) Then
657 sToolbarName = _GetPropertyValue(vUIElements(i),
"UIName
")
661 iObjectsCount = iObjectsCount +
1
663 Case IsMissing(pvIndex)
664 Case VarType(pvIndex) = vbString
665 If UCase(pvIndex) = UCase(sToolbarName) Then bFound = True
667 If pvIndex
< 0 Then Goto Trace_IndexError
668 If pvIndex = iObjectsCount -
1 Then bFound = True
672 Set oObject = _NewCommandBar(vModules(k), sToolbarName, sToolbarFullName, iBuiltin)
673 Set oObject._Window = oWindow.Frame
674 Set oObject._Toolbar = oToolbar
682 ' Find all (not builtin) toolbars stored in current document (typically forms)
683 iBuiltin =
3 ' Stored in form itself
684 Set oToolbar = oWindow.Frame.Controller.Model.getUIConfigurationManager
685 vUIElements() = oToolbar.getUIElementsInfo(
0)
686 For i =
0 To UBound(vUIElements)
687 sToolbarFullName = _GetPropertyValue(vUIElements(i),
"ResourceURL
")
688 sToolbarName = _GetPropertyValue(vUIElements(i),
"UIName
")
689 iObjectsCount = iObjectsCount +
1
691 Case IsMissing(pvIndex)
692 Case VarType(pvIndex) = vbString
693 If UCase(pvIndex) = UCase(sToolbarName) Then bFound = True
695 If pvIndex = iObjectsCount -
1 Then bFound = True
698 Set oObject = _NewCommandBar(
"", sToolbarName, sToolbarFullName, iBuiltin)
699 Set oObject._Window = oWindow.Frame
700 Set oObject._Toolbar = oToolbar
705 ' MISSING : CUSTOM POPUPS
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
708 Case IsMissing(pvIndex)
709 Set oObject = New Collect
710 oObject._CollType = COLLCOMMANDBARS
711 oObject._ParentType = OBJAPPLICATION
712 oObject._Count = iObjectsCount
713 Case VarType(pvIndex) = vbString
715 Case Else
' pvIndex is numeric
716 Goto Trace_IndexError
720 Set CommandBars = oObject
721 Set oObject = Nothing
722 Utils._ResetCalledSub(cstThisSub)
725 TraceError(TRACEABORT, Err, cstThisSub, Erl)
728 TraceError(TRACEFATAL, ERROBJECTNOTFOUND, Utils._CalledSub(),
0, , Array(_GetLabel(
"COMMANDBAR
"), pvIndex))
731 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(),
0)
734 TraceError(TRACEFATAL, ERRWINDOW, Utils._CalledSub(),
0)
736 End Function
' CommandBars V1,
3,
0
738 REM -----------------------------------------------------------------------------------------------------------------------
739 Public Function Controls(ByVal Optional pvObject As Variant, Optional ByVal pvIndex As Variant) As Variant
740 ' Return an object of type Control indicated by either its index (integer) or its name (CASE-INSENSITIVE string)
741 ' The
1st argument pvObject can be either
742 ' an object of type FORM (
1)
743 ' a main form name as string
744 ' an object of type SUBFORM (
2)
745 ' The Form property in the returned variant contains a SUBFORM type
746 ' an object of type CONTROL and subtype GRIDCONTROL (
3)
747 ' an object of type OPTIONGROUP (
4)
2nd argument, if any, must be numeric
748 ' If no pvIndex argument, return a Collection type
750 If _ErrorHandler() Then On Local Error Goto Error_Function
751 Dim vObject As Object
752 Const cstThisSub =
"Controls
"
753 Utils._SetCalledSub(cstThisSub)
755 If IsMissing(pvObject) Then Call _TraceArguments()
756 If IsNull(pvObject) Or IsEmpty(pvObject) Then Call _TraceArguments()
759 If VarType(pvObject) = vbString Then
760 Set vObject = Forms(pvObject)
761 If IsNull(vObject) Then Goto Exit_Function
763 If Not Utils._CheckArgument(pvObject,
1, Array(OBJFORM, OBJSUBFORM, OBJOPTIONGROUP, CTLGRIDCONTROL)) Then Goto Exit_Function
764 Set vObject = pvObject
767 If IsMissing(pvIndex) Then
768 Controls = vObject.Controls()
770 If Not Utils._CheckArgument(pvIndex,
2, Utils._AddNumeric(vbString)) Then Goto Exit_Function
771 Controls = vObject.Controls(pvIndex)
775 Utils._ResetCalledSub(cstThisSub)
778 TraceError(TRACEERROR, Err, cstThisSub, Erl)
780 End Function
' Controls V0.9
.0
782 REM -----------------------------------------------------------------------------------------------------------------------
783 Public Function CurrentDb() As Object
784 ' Returns _A2B_.CurrentDocument().Database as an object to allow access to its properties
786 Const cstThisSub =
"CurrentDb
"
787 Utils._SetCalledSub(cstThisSub)
789 Set CurrentDb = Nothing
790 If IsEmpty(_A2B_) Then GoTo Exit_Function
791 Set CurrentDb = _A2B_.CurrentDb()
794 Utils._ResetCalledSub(cstThisSub)
796 End Function
' CurrentDb V1.1
.0
798 REM -----------------------------------------------------------------------------------------------------------------------
799 Public Function CurrentUser() As String
803 Select Case GetGuiType()
805 CurrentUser = Environ(
"USERNAME
")
807 CurrentUser = Environ(
"USER
")
809 CurrentUser =
""
812 End Function
' CurrentUser V0.9
.1
814 REM -----------------------------------------------------------------------------------------------------------------------
815 Public Function DAvg( _
816 ByVal Optional psExpr As String _
817 , ByVal Optional psDomain As String _
818 , ByVal Optional pvCriteria As Variant _
820 ' Return average of scope
821 Const cstThisSub =
"DAvg
"
822 Utils._SetCalledSub(cstThisSub)
823 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
824 DAvg = Application._CurrentDb()._DFunction(
"AVG
", psExpr, psDomain, Iif(IsMissing(pvCriteria),
"", pvCriteria),
"")
825 Utils._ResetCalledSub(cstThisSub)
826 End Function
' DAvg
828 REM -----------------------------------------------------------------------------------------------------------------------
829 Public Function DCount( _
830 ByVal Optional psExpr As String _
831 , ByVal Optional psDomain As String _
832 , ByVal Optional pvCriteria As Variant _
834 ' Return # of occurrences of scope
835 Const cstThisSub =
"DCount
"
836 Utils._SetCalledSub(cstThisSub)
837 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
838 DCount = Application._CurrentDb()._DFunction(
"COUNT
", psExpr, psDomain, Iif(IsMissing(pvCriteria),
"", pvCriteria),
"")
839 Utils._ResetCalledSub(cstThisSub)
840 End Function
' DCount
842 REM -----------------------------------------------------------------------------------------------------------------------
843 Public Function DLookup( _
844 ByVal Optional psExpr As String _
845 , ByVal Optional psDomain As String _
846 , ByVal Optional pvCriteria As Variant _
847 , ByVal Optional pvOrderClause As Variant _
850 ' Return a value within a table
851 'Arguments: psExpr: an SQL expression
852 ' psDomain: a table- or queryname
853 ' pvCriteria: an optional WHERE clause
854 ' pcOrderClause: an optional order clause incl.
"DESC
" if relevant
855 'Return: Value of the psExpr if found, else Null.
856 'Author: inspired from Allen Browne. http://allenbrowne.com/ser-
42.html
858 ' 1. To find the last value, include DESC in the OrderClause, e.g.:
859 ' DLookup(
"[Surname]
& [FirstName]
",
"tblClient
", ,
"ClientID DESC
")
860 ' 2. To find the lowest non-null value of a field, use the Criteria, e.g.:
861 ' DLookup(
"ClientID
",
"tblClient
",
"Surname Is Not Null
" ,
"Surname
")
863 Const cstThisSub =
"DLookup
"
864 Utils._SetCalledSub(cstThisSub)
865 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
866 DLookup = Application._CurrentDb()._DFunction(
"", psExpr, psDomain _
867 , Iif(IsMissing(pvCriteria),
"", pvCriteria) _
868 , Iif(IsMissing(pvOrderClause),
"", pvOrderClause) _
870 Utils._ResetCalledSub(cstThisSub)
871 End Function
' DLookup
873 REM -----------------------------------------------------------------------------------------------------------------------
874 Public Function DMax( _
875 ByVal Optional psExpr As String _
876 , ByVal Optional psDomain As String _
877 , ByVal Optional pvCriteria As Variant _
879 ' Return maximum of scope
880 Const cstThisSub =
"DMax
"
881 Utils._SetCalledSub(cstThisSub)
882 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
883 DMax = Application._CurrentDb()._DFunction(
"MAX
", psExpr, psDomain, Iif(IsMissing(pvCriteria),
"", pvCriteria),
"")
884 Utils._ResetCalledSub(cstThisSub)
885 End Function
' DMax
887 REM -----------------------------------------------------------------------------------------------------------------------
888 Public Function DMin( _
889 ByVal Optional psExpr As String _
890 , ByVal Optional psDomain As String _
891 , ByVal Optional pvCriteria As Variant _
893 ' Return minimum of scope
894 Const cstThisSub =
"DMin
"
895 Utils._SetCalledSub(cstThisSub)
896 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
897 DMin = Application._CurrentDb()._DFunction(
"MIN
", psExpr, psDomain, Iif(IsMissing(pvCriteria),
"", pvCriteria),
"")
898 Utils._ResetCalledSub(cstThisSub)
899 End Function
' DMin
901 REM -----------------------------------------------------------------------------------------------------------------------
902 Public Function DStDev( _
903 ByVal Optional psExpr As String _
904 , ByVal Optional psDomain As String _
905 , ByVal Optional pvCriteria As Variant _
907 ' Return standard deviation of scope
908 Const cstThisSub =
"DStDev
"
909 Utils._SetCalledSub(cstThisSub)
910 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
911 DStDev = Application._CurrentDb()._DFunction(
"STDDEV_SAMP
", psExpr, psDomain, Iif(IsMissing(pvCriteria),
"", pvCriteria),
"")
' STDDEV not STDEV !
912 Utils._ResetCalledSub(cstThisSub)
913 End Function
' DStDev
915 REM -----------------------------------------------------------------------------------------------------------------------
916 Public Function DStDevP( _
917 ByVal Optional psExpr As String _
918 , ByVal Optional psDomain As String _
919 , ByVal Optional pvCriteria As Variant _
921 ' Return standard deviation of scope
922 Const cstThisSub =
"DStDevP
"
923 Utils._SetCalledSub(cstThisSub)
924 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
925 DStDevP = Application._CurrentDb()._DFunction(
"STDDEV_POP
", psExpr, psDomain, Iif(IsMissing(pvCriteria),
"", pvCriteria),
"")
' STDDEV not STDEV !
926 Utils._ResetCalledSub(cstThisSub)
927 End Function
' DStDevP
929 REM -----------------------------------------------------------------------------------------------------------------------
930 Public Function DSum( _
931 ByVal Optional psExpr As String _
932 , ByVal Optional psDomain As String _
933 , ByVal Optional pvCriteria As Variant _
935 ' Return sum of scope
936 Const cstThisSub =
"DSum
"
937 Utils._SetCalledSub(cstThisSub)
938 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
939 DSum = Application._CurrentDb()._DFunction(
"SUM
", psExpr, psDomain, Iif(IsMissing(pvCriteria),
"", pvCriteria),
"")
940 Utils._ResetCalledSub(cstThisSub)
941 End Function
' DSum
943 REM -----------------------------------------------------------------------------------------------------------------------
944 Public Function DVar( _
945 ByVal Optional psExpr As String _
946 , ByVal Optional psDomain As String _
947 , ByVal Optional pvCriteria As Variant _
949 ' Return variance of scope
950 Const cstThisSub =
"DVar
"
951 Utils._SetCalledSub(cstThisSub)
952 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
953 DVar = Application._CurrentDb()._DFunction(
"VAR_SAMP
", psExpr, psDomain, Iif(IsMissing(pvCriteria),
"", pvCriteria),
"")
954 Utils._ResetCalledSub(cstThisSub)
955 End Function
' DVar
957 REM -----------------------------------------------------------------------------------------------------------------------
958 Public Function DVarP( _
959 ByVal Optional psExpr As String _
960 , ByVal Optional psDomain As String _
961 , ByVal Optional pvCriteria As Variant _
963 ' Return variance of scope
964 Const cstThisSub =
"DVarP
"
965 Utils._SetCalledSub(cstThisSub)
966 If IsMissing(psExpr) Or IsMissing(psDomain) Then Call _TraceArguments()
967 DVarP = Application._CurrentDb()._DFunction(
"VAR_POP
", psExpr, psDomain, Iif(IsMissing(pvCriteria),
"", pvCriteria),
"")
968 Utils._ResetCalledSub(cstThisSub)
969 End Function
' DVarP
971 REM -----------------------------------------------------------------------------------------------------------------------
972 Public Function Events(Optional poEvent As Variant) As Variant
973 ' Return an event object corresponding with actual event
975 Dim vEvent As Variant
976 If _ErrorHandler() Then On Local Error Goto Error_Function
977 Const cstThisSub =
"Events
"
978 Utils._SetCalledSub(cstThisSub)
981 If IsMissing(poEvent) Then Goto Exit_Function
982 If IsNull(poEvent) Then Goto Exit_Function
984 If Not Utils._CheckArgument(poEvent,
1, vbObject, , False) Then Goto Exit_Function
' No error handling in CheckArgument
985 If Not Utils._hasUNOProperty(poEvent,
"Source
") Then Goto Trace_Error
986 Set vEvent = New Event
987 vEvent._Initialize(poEvent)
991 Utils._ResetCalledSub(cstThisSub)
994 TraceError(TRACEWARNING, Err, cstThisSub, Erl)
997 ' Errors are not displayed to avoid display infinite cycling
998 TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(),
0, False, Array(
1, Utils._CStr(poEvent)))
1001 End Function
' Events V0.9
.1
1003 REM -----------------------------------------------------------------------------------------------------------------------
1004 Public Function Forms(ByVal Optional pvIndex As Variant) As Variant
1005 ' Return an object of type Form indicated by either its index (integer) or its name (NOT CASE-SENSITIVE string)
1006 ' The concerned form must be loaded.
1007 ' If no argument, return a Collection type
1009 Const cstThisSub =
"Forms
"
1010 Utils._SetCalledSub(cstThisSub)
1011 If _ErrorHandler() Then On Local Error Goto Error_Function
1013 Dim ofForm As Object, oCounter As Variant, vForms As Variant, oIndex As Object
1014 Set vForms = Nothing
1016 Dim iCount As Integer
1017 If IsMissing(pvIndex) Then
1018 iCount = Application._CountOpenForms()
1019 Set oCounter = New Collect
1020 oCounter._CollType = COLLFORMS
1021 oCounter._ParentType = OBJAPPLICATION
1022 oCounter._ParentName =
""
1023 oCounter._Count = iCount
1027 If Not Utils._CheckArgument(pvIndex,
1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
1030 Select Case VarType(pvIndex)
1032 Set ofForm = Application.AllForms(Utils._Trim(pvIndex))
1033 Case vbInteger, vbLong, vbSingle, vbDouble, vbCurrency, vbBigint, vbDecimal
1034 iCount = Application._CountOpenForms()
1035 If iCount
<= pvIndex Then Goto Trace_Error_Index
1036 Set ofForm = Application._CountOpenForms(pvIndex)
1040 If IsNull(ofForm) Then Goto Trace_Error
1041 If ofForm.IsLoaded Then
1044 Set vForms = Nothing
1045 TraceError(TRACEFATAL, ERRFORMNOTOPEN, Utils._CalledSub(),
0, , ofForm._Name)
1051 Utils._ResetCalledSub(cstThisSub)
1054 TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(),
0, , Array(
1, pvIndex))
1055 Set vForms = Nothing
1058 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(),
0,
1)
1059 Set vForms = Nothing
1062 TraceError(TRACEABORT, Err, cstThisSub, Erl)
1064 End Function
' Forms V0.9
.0
1066 REM -----------------------------------------------------------------------------------------------------------------------
1067 Function HtmlEncode(ByVal pvString As Variant, ByVal Optional pvLength As Variant) As String
1068 ' Converts a string to an HTML-encoded string.
1070 If _ErrorHandler() Then On Local Error Goto Error_Function
1071 Const cstThisSub =
"HtmlEncode
"
1072 Utils._SetCalledSub(cstThisSub)
1074 HtmlEncode =
""
1076 Dim sOutput As String, l As Long, lLength As Long
1077 If IsMissing(pvLength) Then pvLength =
0
1078 If Not Utils._CheckArgument(pvString,
1, vbString) Then Goto Exit_Function
1079 If Not Utils._CheckArgument(pvLength,
1, _AddNumeric()) Then Goto Exit_Function
1081 sOutput =
""
1082 lLength = CLng(pvLength)
1083 If Len(pvString)
> 0 Then
1084 For l =
1 To Len(pvString)
1085 If lLength
> 0 And Len(sOutput)
> lLength Then Exit For
1086 sOutput = sOutput
& Utils._UTF8Encode(Mid(pvString, l,
1))
1090 HtmlEncode = sOutput
1093 Utils._ResetCalledSub(cstThisSub)
1096 TraceError(TRACEABORT, Err, cstThisSub, Erl)
1098 End Function
' HtmlEncode V1.4
.0
1100 REM -----------------------------------------------------------------------------------------------------------------------
1101 Public Function OpenConnection ( _
1102 Optional pvComponent As Variant _
1103 , ByVal Optional pvUser As Variant _
1104 , ByVal Optional pvPassword As Variant _
1107 ' Establish connection with the database designated in the currently open front-end (.odb) document
1108 ' Call template:
1109 ' Call OpenConnection(ThisDatabaseDocument[,
"",
""])
1110 ' Call stored in the OpenDocument event of the front-end database document
1112 ' Initiates processing of a (standalone ?) Writer, Calc, ... document with
1 or more data-aware forms
1113 ' Call template:
1114 ' Call OpenConnection(ThisComponent[,
"",
""])
1115 ' Call stored in the OpenDocument event of the document
1117 ' User and Password arguments are obsolete (still tolerated)
1118 ' - because no mean has been found to connect protected db from .odb via API
1119 ' - because having multiple forms with multiple db
's and multiple passwords is meaningless
1121 Dim oComponent As Object, oForms As Object, iCurrent As Integer
1122 Dim i As Integer, bFound As Boolean
1123 Dim vCurrentDoc() As Variant
1124 Dim oBaseContext As Object, sDbNames() As String, oBaseSource As Object
1125 Dim sDatabaseURL As String, oHandler As Object
1126 Dim vDbContainer As Variant, vDbContainers() As Variant, vDocContainer As Variant
1127 Dim sFormName As String
1129 If IsEmpty(_A2B_) Then Call Application._RootInit()
' First use of Access2Base in current AOO/LibO session
1130 Set OpenConnection = Nothing
1132 If _ErrorHandler() Then On Local Error Goto Error_Function
1133 Const cstThisSub =
"OpenConnection
"
1134 Utils._SetCalledSub(cstThisSub)
1135 If IsMissing(pvComponent) Then Call _TraceArguments()
1136 If Not Utils._CheckArgument(pvComponent,
1, vbObject) Then Goto Exit_Function
1137 Set oComponent = pvComponent
1138 If Not Utils._hasUNOProperty(oComponent,
"ImplementationName
") Then
1139 TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(),
0,
1, Array(
1, oComponent))
1142 If IsMissing(pvUser) Then pvUser =
""
1143 If IsMissing(pvPassword) Then pvPassword =
""
1144 If Not Utils._CheckArgument(pvUser,
2, vbString) Then Goto Exit_Function
1145 If Not Utils._CheckArgument(pvPassword,
3, vbString) Then Goto Exit_Function
1147 If Not IsArray(_A2B_.CurrentDoc) Then
1148 vCurrentDoc() = Array()
1149 Redim vCurrentDoc(
0 To
0)
' Create at least one entry for database document
1151 vCurrentDoc() = _A2B_.CurrentDoc()
1154 ' Find index of entry to use for new connection
1156 Select Case .ImplementationName
1157 Case
"com.sun.star.comp.dba.ODatabaseDocument
"
1159 Case Else
' "SwXTextDocument
",
"ScModelObj
"
1160 If UBound(vCurrentDoc)
<=
0 Then
' First Calc or Writer during current session
1162 Else
' Search entry already used earlier by same component
1164 For i =
1 To UBound(vCurrentDoc)
1165 If Not IsEmpty(vCurrentDoc(i)) Then
1166 If vCurrentDoc(i).Active And vCurrentDoc(i).URL = .URL Then
1175 iCurrent = UBound(vCurrentDoc) +
1 ' No entry found, increment array
1176 ReDim Preserve vCurrentDoc(
0 To iCurrent)
1181 ' Initialize future entry
1182 Set vDocContainer = New DocContainer
1183 Set vDocContainer.Document = oComponent
1184 vDocContainer.Active = True
1185 vDocContainer.URL = oComponent.URL
1186 ' Initialize each DbContainer entry
1187 vDbContainers() = Array()
1188 TraceLog(TRACEANY, Utils._GetProductName()
& " -
" & Application.ProductCode(), False)
1189 Select Case oComponent.ImplementationName
1190 Case
"com.sun.star.comp.dba.ODatabaseDocument
" ' Ignore pvUser and pvPassword arguments
1191 vDbContainer = New DbContainer
1192 vDbContainer.FormName =
""
1193 Set vDbContainer.Database = New Database
1194 Set vDbContainer.Database._This = vDbContainer.Database
1195 With vDbContainer.Database
1196 If Not oComponent.CurrentController.IsConnected Then
1197 Set oHandler = createUnoService(
"com.sun.star.sdb.InteractionHandler
")
1198 Set .Connection = oComponent.DataSource.connectWithCompletion(oHandler)
1199 oComponent.CurrentController.connect()
1201 Set .Connection = oComponent.CurrentController.ActiveConnection
1203 vDocContainer.DbConnect = DBCONNECTBASE
1204 ._DbConnect = DBCONNECTBASE
1205 Set .MetaData = .Connection.MetaData
1207 If .MetaData.DatabaseProductName =
"MySQL
" Then
1208 ._ReadOnly = .MetaData.isReadOnly()
1210 ._ReadOnly = .Connection.isReadOnly()
' Always True in Mysql ??
1212 Set .Document = oComponent
1213 .Title = oComponent.Title
1214 .URL = vDocContainer.URL
1215 ReDim vDbContainers(
0 To
0)
1216 Set vDbContainers(
0) = vDbContainer
1217 TraceLog(TRACEANY, .Version, False)
1218 TraceLog(TRACEANY, UCase(cstThisSub)
& " " & .URL, False)
1221 Set oForms = oComponent.CurrentController.Model.DrawPage.Forms
1222 If oForms.Count
< 1 Then Goto Error_MainForm
1223 ReDim vDbContainers(
0 To oForms.Count -
1)
1224 For i =
0 To oForms.Count -
1
1225 vDbContainer = New DbContainer
' To make distinct entries !!
1226 sFormName = oForms.ElementNames(i)
1227 Set vDbContainer.Database = New Database
1228 Set vDbContainer.Database._This = vDbContainer.Database
1229 With vDbContainer.Database
1230 .FormName = sFormName
1231 vDbContainer.FormName = sFormName
1232 Set .Form = oForms.getByName(sFormName)
1233 Set .Connection = .Form.ActiveConnection
' Might be Nothing in Windows at AOO/LO startup (not met in Linux)
1234 If Not IsNull(.Connection) Then
1235 Set .MetaData = .Connection.MetaData
1237 ._ReadOnly = .Connection.isReadOnly()
1238 TraceLog(TRACEANY, .MetaData.getDatabaseProductName()
& " " & .MetaData.getDatabaseProductVersion, False)
1240 Set .Document = oComponent
1241 .Title = oComponent.Title
1242 .URL = .Form.DataSourceName
1243 ._DbConnect = DBCONNECTFORM
1244 Set vDbContainers(i) = vDbContainer
1245 vDbContainers(i).FormName = sFormName
1246 TraceLog(TRACEANY, UCase(cstThisSub)
& " " & .URL
& " Form=
" & vDbContainer.FormName, False)
1249 vDocContainer.DbConnect = DBCONNECTFORM
1252 vDocContainer.DbContainers() = vDbContainers()
1253 Set vCurrentDoc(iCurrent) = vDocContainer
1255 _A2B_.CurrentDoc = vCurrentDoc
1256 Set OpenConnection = vDbContainers(
0).Database
1260 Utils._ResetCalledSub(cstThisSub)
1263 TraceError(TRACEABORT, Err, cstThisSub, Erl)
1264 Set _A2B_.CurrentDoc = Array()
1267 TraceError(TRACEFATAL, ERRMAINFORM, Utils._CalledSub(), False, ,oComponent.Title)
1268 Set _A2B_.CurrentDoc = Array()
1271 TraceError(TRACEABORT, ERRDBNOTCONNECTED, Utils._CalledSub(),
0,
1)
1273 End Function
' OpenConnection V1.1
.0
1275 REM -----------------------------------------------------------------------------------------------------------------------
1276 Public Function OpenDatabase ( _
1277 ByVal Optional pvDatabaseURL As Variant _
1278 , ByVal Optional pvUser As Variant _
1279 , ByVal Optional pvPassword As Variant _
1280 , ByVal Optional pvReadOnly As Variant _
1283 ' Return a database object based on input arguments:
1284 ' Call template:
1285 ' Call OpenDatabase(
"... databaseURL ...
"[,
"",
"", True/False])
1286 ' pvDatabaseURL maby be the name of a registered database or the URL of the targeted .odb file
1287 ' Might be called from any AOO/LibO application, independently from OpenConnection
1289 Dim odbDatabase As Variant, oBaseContext As Object, sDbNames() As String, oBaseSource As Object
1290 Dim i As Integer, bFound As Boolean
1291 Dim sDatabaseURL As String
1293 If IsEmpty(_A2B_) Then
' First use of Access2Base in current AOO/LibO session
1294 Call Application._RootInit()
1295 TraceLog(TRACEANY, Utils._GetProductName()
& " -
" & Application.ProductCode(), False)
1297 Set OpenDatabase = Nothing
1299 If _ErrorHandler() Then On Local Error Goto Error_Function
1300 Const cstThisSub =
"OpenDatabase
"
1301 Utils._SetCalledSub(cstThisSub)
1302 If pvDatabaseURL =
"" Then Call _TraceArguments()
1303 If Not Utils._CheckArgument(pvDatabaseURL,
1, vbString) Then Goto Exit_Function
1304 If IsMissing(pvUser) Then pvUser =
""
1305 If IsMissing(pvPassword) Then pvPassword =
""
1306 If Not Utils._CheckArgument(pvUser,
2, vbString) Then Goto Exit_Function
1307 If Not Utils._CheckArgument(pvPassword,
3, vbString) Then Goto Exit_Function
1308 If IsMissing(pvReadOnly) Then pvReadOnly = False
1309 If Not Utils._CheckArgument(pvReadOnly,
3, vbBoolean) Then Goto Exit_Function
1311 Set odbDatabase = New Database
1312 Set odbDatabase._This = odbDatabase
1313 odbDatabase._DbConnect = DBCONNECTANY
1315 Set oBaseContext = CreateUnoService(
"com.sun.star.sdb.DatabaseContext
")
1316 sDbNames() = oBaseContext.getElementNames()
1318 For i =
0 To UBound(sDbNames())
' Enumerate registered databases and check non case-sensitive equality
1319 If UCase(sDbNames(i)) = UCase(pvDatabaseURL) Then
1320 sDatabaseURL = sDbNames(i)
1321 Set oBaseSource = oBaseContext.getByName(sDatabaseURL)
1327 sDatabaseURL = ConvertToURL(pvDatabaseURL)
1328 If UCase(Right(sDatabaseURL,
4))
<> ".ODB
" Then Goto Trace_Error
1329 If Not FileExists(sDatabaseURL) Then Goto Trace_Error
1330 Set oBaseSource = oBaseContext.getByName(sDatabaseURL)
1333 Set odbDatabase.Connection = oBaseSource.getConnection(pvUser, pvPassword)
1334 If Not IsNull(odbDatabase.Connection) Then
' Null when standalone and target db does not exist
1335 Set odbDatabase.MetaData = odbDatabase.Connection.MetaData
1336 odbDatabase._LoadMetadata()
1341 odbDatabase.URL = sDatabaseURL
1344 odbDatabase.Connection.isReadOnly = True
1345 odbDatabase._ReadOnly = True
1348 Set OpenDatabase = odbDatabase
1350 TraceLog(TRACEANY, odbDatabase.MetaData.getDatabaseProductName()
& " " & odbDatabase.MetaData.getDatabaseProductVersion, False)
1351 TraceLog(TRACEANY, UCase(cstThisSub)
& " " & odbDatabase.URL, False)
1355 Utils._ResetCalledSub(cstThisSub)
1358 TraceError(TRACEABORT, Err, cstThisSub, Erl)
1361 TraceError(TRACEABORT, ERRDBNOTCONNECTED, Utils._CalledSub(),
0,
1)
1363 End Function
' OpenDatabase V1.1
.0
1365 REM -----------------------------------------------------------------------------------------------------------------------
1366 Public Function ProductCode()
1367 If IsEmpty(_A2B_) Then Call Application._RootInit()
' First use of Access2Base in current AOO/LibO session
1368 ProductCode =
"Access2Base
" & _A2B_.VersionNumber
1369 End Function
' ProductCode V0.9
.1
1371 REM -----------------------------------------------------------------------------------------------------------------------
1372 Public Function SysCmd(Optional pvAction As Variant _
1373 , Optional pvText As Variant _
1374 , Optional pvValue As Variant _
1376 ' Manage progress meter in the status bar
1377 ' Other values supported by MSAccess are ignored
1379 If _ErrorHandler() Then On Local Error Goto Error_Function
1380 Const cstThisSub =
"SysCmd
"
1381 Utils._SetCalledSub(cstThisSub)
1384 Const cstMissing = -
1
1385 Const cstBarLength =
350
1386 If IsMissing(pvAction) Then Call _TraceArguments()
1387 If Not Utils._CheckArgument(pvAction,
1, Utils._AddNumeric(), Array( _
1389 , acSysCmdAccessVer _
1390 , acSysCmdClearHelpTopic _
1391 , acSysCmdClearStatus _
1392 , acSysCmdGetObjectState _
1393 , acSysCmdGetWorkgroupFile _
1395 , acSysCmdInitMeter _
1397 , acSysCmdRemoveMeter _
1399 , acSysCmdSetStatus _
1400 , acSysCmdUpdateMeter _
1401 )) Then Goto Exit_Function
1402 If IsMissing(pvValue) Then pvValue = cstMissing
1403 If Not Utils._CheckArgument(pvAction,
1, Utils._AddNumeric()) Then Goto Exit_Function
1404 Select Case pvAction
1405 Case acSysCmdInitMeter, acSysCmdUpdateMeter, acSysCmdSetStatus
1406 If IsMissing(pvText) Then Call _TraceArguments()
1407 If Not Utils._CheckArgument(pvText,
2, vbString) Then Goto Exit_Function
1410 If Not Utils._CheckArgument(pvValue,
3, Utils._AddNumeric()) Then Goto Exit_Function
1412 Dim vBar As Variant, iLen As Integer
1413 Set vBar = _A2B_.StatusBar
1414 Select Case pvAction
1415 Case acSysCmdAccessVer
1416 SysCmd = Application.Version()
1418 Case acSysCmdSetStatus
1419 If pvValue
<> cstMissing Then Goto Error_Arg
1422 If Not IsNull(vBar) Then vBar.start(Iif(iLen
>= cstBarLength, pvText, pvText
& Space(cstBarLength - iLen)),
0)
1423 Case acSysCmdClearStatus
1424 If pvValue
<> cstMissing Then Goto Error_Arg
1425 If Not IsNull(vBar) Then
1427 Set _A2B_.StatusBar = Nothing
1429 Case acSysCmdInitMeter
1430 If pvValue = cstMissing Then Call _TraceArguments()
1432 If Not IsNull(vBar) Then vBar.start(pvText, pvValue)
1433 Case acSysCmdUpdateMeter
1434 If pvValue = cstMissing Then Call _TraceArguments()
1435 If Not IsNull(vBar) Then
' Otherwise ignore !
1436 vBar.setValue(pvValue)
1437 If Len(pvText)
> 0 Then vBar.setText(pvText)
1439 Case acSysCmdRemoveMeter
1440 If Not IsNull(vBar) Then
1442 Set _A2B_.StatusBar = Nothing
1444 Case acSysCmdRuntime
1453 Utils._ResetCalledSub(cstThisSub)
1456 TraceError(TRACEABORT, Err, cstThisSub, Erl)
1459 TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(),
0,
1, Array(
3, pvValue))
1461 End Function
' SysCmd V0.9
.1
1463 REM -----------------------------------------------------------------------------------------------------------------------
1464 Public Function TempVars(ByVal Optional pvIndex As Variant) As Variant
1465 ' Return either a Collection or a TempVar object
1467 If _ErrorHandler() Then On Local Error Goto Error_Function
1468 Const cstThisSub =
"TempVars
"
1469 Utils._SetCalledSub(cstThisSub)
1471 Dim iMode As Integer, vTempVars As Variant, bFound As Boolean
1473 Const cstByIndex =
1
1476 If IsMissing(pvIndex) Then
1479 If Not Utils._CheckArgument(pvIndex,
1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
1480 If VarType(pvIndex) = vbString Then iMode = cstByName Else iMode = cstByIndex
1483 Set vTempVars = Nothing
1485 Case cstCount
' Build Collection object
1486 Set vTempVars = New Collect
1488 ._CollType = COLLTEMPVARS
1489 ._Count = _A2B_.TempVars.Count
1491 Case cstByIndex
' Build TempVar object
1492 If pvIndex
< 0 Or pvIndex
>= _A2B_.TempVars.Count Then Goto Trace_Error_Index
1493 Set vTempVars = _A2B_.TempVars.Item(pvIndex +
1)
' Builtin collections start at
1
1495 bFound = _A2B_.hasItem(COLLTEMPVARS, pvIndex)
1496 If Not bFound Then Goto Trace_NotFound
1497 vTempVars = _A2B_.TempVars.Item(UCase(pvIndex))
1500 Set TempVars = vTempVars
1503 Utils._ResetCalledSub(cstThisSub)
1506 TraceError(TRACEABORT, Err, cstThisSub, Erl)
1509 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(),
0,
1)
1510 Set vTempVars = Nothing
1513 TraceError(TRACEFATAL, ERROBJECTNOTFOUND, Utils._CalledSub(),
0, , Array(_GetLabel(
"TEMPVAR
"), pvIndex))
1515 End Function
' TempVars V1.2
.0
1517 REM -----------------------------------------------------------------------------------------------------------------------
1518 Public Function Version() As String
1519 Version = Utils._GetProductName()
1520 End Function
' Version V0.9
.1
1522 REM -----------------------------------------------------------------------------------------------------------------------
1523 REM --- PRIVATE FUNCTIONS ---
1524 REM -----------------------------------------------------------------------------------------------------------------------
1526 REM -----------------------------------------------------------------------------------------------------------------------
1527 Public Function _CountOpenForms(ByVal Optional piCountMax As Integer) As Variant
1528 ' Return # of active forms if no argument
1529 ' Return name of piCountMax-th open form if argument present
1531 Dim i As Integer, iCount As Integer, iAllCount As Integer, ofForm As Variant
1532 iAllCount = AllForms._Count
1534 If iAllCount
> 0 Then
1535 For i =
0 To iAllCount -
1
1536 Set ofForm = Application.AllForms(i)
1537 If ofForm.IsLoaded Then iCount = iCount +
1
1538 If Not IsMissing(piCountMax) Then
1539 If iCount = piCountMax +
1 Then
1540 _CountOpenForms = ofForm
' OO3.2 aborts when Set verb present ?!?
1547 If IsMissing(piCountMax) Then _CountOpenForms = iCount
1549 End Function
' CountOpenForms V1.1
.0
1551 REM -----------------------------------------------------------------------------------------------------------------------
1552 Public Function _CurrentDb(ByVal Optional piDocEntry As Integer, ByVal Optional piDbEntry As Integer) As Variant
1553 REM Without arguments same as CurrentDb() except that it generates an error if database not connected (internal use)
1554 REM With
2 arguments return the corresponding entry in Root
1556 Dim oCurrentDb As Object
1557 If IsEmpty(_A2B_) Then GoTo Trace_Error
1558 If IsMissing(piDocEntry) Then Set oCurrentDb = Application.CurrentDb() _
1559 Else Set oCurrentDb = _A2B_._CurrentDb(piDocEntry, piDbEntry)
1560 If IsNull(oCurrentDb) Then Goto Trace_Error Else Set _CurrentDb = oCurrentDb
1565 TraceError(TRACEABORT, ERRDBNOTCONNECTED, Utils._CalledSub(),
0,
1)
1567 End Function
' _CurrentDb V1.1
.0
1569 REM -----------------------------------------------------------------------------------------------------------------------
1570 Private Function _NewBar() As Object
1571 ' Close current status bar, if any, and initialize new one
1573 Dim vBar As Variant, vWindow As Variant, vController As Object
1574 On Local Error Resume Next
1575 Set _NewBar = Nothing
1577 Set vBar = _A2B_.StatusBar
1578 If Not IsNull(vBar) Then
1579 If Utils._hasUNOMethod(vBar,
"end
") Then vBar.end()
1580 Set _A2B_.StatusBar = Nothing
1584 Set vWindow = _SelectWindow()
1585 If IsNull(vWindow.Frame) Then Exit Function
1586 Select Case vWindow.WindowType
1587 Case acForm, acReport, acBasicIDE, acDocument
' Not found how to make it work for acDatabaseWindow
1591 If Utils._hasUNOMethod(vWindow.Frame,
"getCurrentController
") Then
1592 Set vController = vWindow.Frame.getCurrentController()
1593 ElseIf Utils._hasUNOMethod(vWindow.Frame,
"getController
") Then
1594 Set vController = vWindow.Frame.getController()
1597 If Utils._hasUNOMethod(vController,
"getStatusIndicator
") Then vBar = vController.getStatusIndicator()
1598 Set _A2B_.StatusBar = vBar
1602 End Function
' _NewBar V1.1
.0
1604 REM -----------------------------------------------------------------------------------------------------------------------
1605 Private Function _NewCommandBar(psModule As String _
1606 , psToolbarName As String _
1607 , psToolbarFullName As String _
1608 , piBuiltin As Integer _
1611 Dim oObject As Object
1612 Set oObject = New CommandBar
1614 ._Type = OBJCOMMANDBAR
1615 ._Name = psToolbarName
1616 ._ResourceURL = psToolbarFullName
1618 ._BarBuiltin = piBuiltin
1619 Select Case UCase(Split(psToolbarFullName,
"/
")(
1))
1620 Case
"MENUBAR
" : ._BarType = msoBarTypeMenuBar
1621 Case
"STATUSBAR
" : ._BarType = msoBarTypeStatusBar
1622 Case
"TOOLBAR
" : ._BarType = msoBarTypeNormal
1623 Case
"POPUP
" : ._BarType = msoBarTypePopup
1624 Case
"FLOATER
" : ._BarType = msoBarTypeFloater
1625 Case Else : ._BarType = -
1
1628 Set _NewCommandBar = oObject
1631 End Function
' NewCommandBar V1.3
.0
1633 REM -----------------------------------------------------------------------------------------------------------------------
1634 Public Sub _RootInit(Optional ByVal pbForce As Boolean)
1635 ' Initialize _A2B_ global variable. Reinit forced if pbForce = True
1637 If IsMissing(pbForce) Then pbForce = False
1638 If IsEmpty(_A2B_) Or pbForce Then _A2B_ = New Root_
1640 End Sub
' _RootInit V1.1
.0