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=
"SubForm" 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 =======================================================================================================================
13 REM -----------------------------------------------------------------------------------------------------------------------
14 REM --- CLASS ROOT FIELDS ---
15 REM -----------------------------------------------------------------------------------------------------------------------
17 Private _Type As String
' Must be SUBFORM
18 Private _Shortcut As String
19 Private _Name As String
20 Private _DocEntry As Integer
21 Private _DbEntry As Integer
22 Private _OrderBy As String
23 Public ParentComponent As Object
' com.sun.star.text.TextDocument
24 Public DatabaseForm As Object
' com.sun.star.form.component.DataForm and com.sun.star.sdb.ResultSet (a.o.)
26 REM -----------------------------------------------------------------------------------------------------------------------
27 REM --- CONSTRUCTORS / DESTRUCTORS ---
28 REM -----------------------------------------------------------------------------------------------------------------------
29 Private Sub Class_Initialize()
31 _Shortcut =
""
35 _OrderBy =
""
36 Set ParentComponent = Nothing
37 Set DatabaseForm = Nothing
38 End Sub
' Constructor
40 REM -----------------------------------------------------------------------------------------------------------------------
41 Private Sub Class_Terminate()
42 On Local Error Resume Next
43 Call Class_Initialize()
44 End Sub
' Destructor
46 REM -----------------------------------------------------------------------------------------------------------------------
48 Call Class_Terminate()
49 End Sub
' Explicit destructor
51 REM -----------------------------------------------------------------------------------------------------------------------
52 REM --- CLASS GET/LET/SET PROPERTIES ---
53 REM -----------------------------------------------------------------------------------------------------------------------
54 Property Get AllowAdditions() As Variant
55 AllowAdditions = _PropertyGet(
"AllowAdditions
")
56 End Property
' AllowAdditions (get)
58 Property Let AllowAdditions(ByVal pvValue As Variant)
59 Call _PropertySet(
"AllowAdditions
", pvValue)
60 End Property
' AllowAdditions (set)
62 REM -----------------------------------------------------------------------------------------------------------------------
63 Property Get AllowDeletions() As Variant
64 AllowDeletions = _PropertyGet(
"AllowDeletions
")
65 End Property
' AllowDeletions (get)
67 Property Let AllowDeletions(ByVal pvValue As Variant)
68 Call _PropertySet(
"AllowDeletions
", pvValue)
69 End Property
' AllowDeletions (set)
71 REM -----------------------------------------------------------------------------------------------------------------------
72 Property Get AllowEdits() As Variant
73 AllowEdits = _PropertyGet(
"AllowEdits
")
74 End Property
' AllowEdits (get)
76 Property Let AllowEdits(ByVal pvValue As Variant)
77 Call _PropertySet(
"AllowEdits
", pvValue)
78 End Property
' AllowEdits (set)
80 REM -----------------------------------------------------------------------------------------------------------------------
81 Property Get CurrentRecord() As Variant
82 CurrentRecord = _PropertyGet(
"CurrentRecord
")
83 End Property
' CurrentRecord (get)
85 Property Let CurrentRecord(ByVal pvValue As Variant)
86 Call _PropertySet(
"CurrentRecord
", pvValue)
87 End Property
' CurrentRecord (set)
89 REM -----------------------------------------------------------------------------------------------------------------------
90 Property Get Filter() As Variant
91 Filter = _PropertyGet(
"Filter
")
92 End Property
' Filter (get)
94 Property Let Filter(ByVal pvValue As Variant)
95 Call _PropertySet(
"Filter
", pvValue)
96 End Property
' Filter (set)
98 REM -----------------------------------------------------------------------------------------------------------------------
99 Property Get FilterOn() As Variant
100 FilterOn = _PropertyGet(
"FilterOn
")
101 End Property
' FilterOn (get)
103 Property Let FilterOn(ByVal pvValue As Variant)
104 Call _PropertySet(
"FilterOn
", pvValue)
105 End Property
' FilterOn (set)
107 REM -----------------------------------------------------------------------------------------------------------------------
108 Property Get LinkChildFields(ByVal Optional pvIndex As Variant) As Variant
109 If IsMissing(pvIndex) Then LinkChildFields = _PropertyGet(
"LinkChildFields
") Else LinkChildFields = _PropertyGet(
"LinkChildFields
", pvIndex)
110 End Property
' LinkChildFields (get)
112 REM -----------------------------------------------------------------------------------------------------------------------
113 Property Get LinkMasterFields(ByVal Optional pvIndex As Variant) As Variant
114 If IsMissing(pvIndex) Then LinkMasterFields = _PropertyGet(
"LinkMasterFields
") Else LinkMasterFields = _PropertyGet(
"LinkMasterFields
", pvIndex)
115 End Property
' LinkMasterFields (get)
117 REM -----------------------------------------------------------------------------------------------------------------------
118 Property Get Name() As String
119 Name = _PropertyGet(
"Name
")
120 End Property
' Name (get)
122 Public Function pName() As String
' For compatibility with
< V0.9
.0
123 pName = _PropertyGet(
"Name
")
124 End Function
' pName (get)
126 REM -----------------------------------------------------------------------------------------------------------------------
127 Property Get ObjectType() As String
128 ObjectType = _PropertyGet(
"ObjectType
")
129 End Property
' ObjectType (get)
131 REM -----------------------------------------------------------------------------------------------------------------------
132 Public Function OptionGroup(ByVal Optional pvGroupName As Variant) As Variant
133 ' Return either an error or an object of type OPTIONGROUP based on its name
135 Const cstThisSub =
"SubForm.OptionGroup
"
136 Dim ogGroup As Object
137 Utils._SetCalledSub(cstThisSub)
138 If IsMissing(pvGroupName) Then Call _TraceArguments()
139 If _ErrorHandler() Then On Local Error Goto Error_Function
141 Set ogGroup = _OptionGroup(pvGroupName, CTLPARENTISSUBFORM, ParentComponent, DatabaseForm)
142 If Not IsNull(ogGroup) Then
143 ogGroup._DocEntry = _DocEntry
144 ogGroup._DbEntry = _DbEntry
146 Set OptionGroup = ogGroup
149 Utils._ResetCalledSub(cstThisSub)
152 TraceError(TRACEABORT, Err, cstThisSub, Erl)
154 End Function
' OptionGroup V1.1
.0
156 REM -----------------------------------------------------------------------------------------------------------------------
157 Property Get OrderBy() As Variant
158 OrderBy = _PropertyGet(
"OrderBy
")
159 End Property
' OrderBy (get) V1.2
.0
161 Property Let OrderBy(ByVal pvValue As Variant)
162 Call _PropertySet(
"OrderBy
", pvValue)
163 End Property
' OrderBy (set)
165 REM -----------------------------------------------------------------------------------------------------------------------
166 Property Get OrderByOn() As Variant
167 OrderByOn = _PropertyGet(
"OrderByOn
")
168 End Property
' OrderByOn (get) V1.2
.0
170 Property Let OrderByOn(ByVal pvValue As Variant)
171 Call _PropertySet(
"OrderByOn
", pvValue)
172 End Property
' OrderByOn (set)
174 REM -----------------------------------------------------------------------------------------------------------------------
175 Public Function Parent() As Object
177 Utils._SetCalledSub(
"SubForm.getParent
")
178 On Error Goto Error_Function
180 Set Parent = PropertiesGet._ParentObject(_Shortcut)
183 Utils._ResetCalledSub(
"SubForm.getParent
")
186 TraceError(TRACEABORT, Err,
"SubForm.getParent
", Erl)
189 End Function
' Parent
191 REM -----------------------------------------------------------------------------------------------------------------------
192 Public Function Properties(ByVal Optional pvIndex As Variant) As Variant
194 ' a Collection object if pvIndex absent
195 ' a Property object otherwise
197 Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String
198 vPropertiesList = _PropertiesList()
199 sObject = Utils._PCase(_Type)
200 If IsMissing(pvIndex) Then
201 vProperty = PropertiesGet._Properties(sObject, _Name, vPropertiesList)
203 vProperty = PropertiesGet._Properties(sObject, _Name, vPropertiesList, pvIndex)
204 vProperty._Value = _PropertyGet(vPropertiesList(pvIndex))
208 Set Properties = vProperty
210 End Function
' Properties
212 REM -----------------------------------------------------------------------------------------------------------------------
213 Property Get Recordset() As Object
214 Recordset = _PropertyGet(
"Recordset
")
215 End Property
' Recordset (get) V0.9
.5
217 REM -----------------------------------------------------------------------------------------------------------------------
218 Property Get RecordSource() As Variant
219 RecordSource = _PropertyGet(
"RecordSource
")
220 End Property
' RecordSource (get)
222 Property Let RecordSource(ByVal pvValue As Variant)
223 Call _PropertySet(
"RecordSource
", pvValue)
224 End Property
' RecordSource (set)
226 REM -----------------------------------------------------------------------------------------------------------------------
227 REM --- CLASS METHODS ---
228 REM -----------------------------------------------------------------------------------------------------------------------
229 Public Function Controls(Optional ByVal pvIndex As Variant) As Variant
230 ' Return a Control object with name or index = pvIndex
232 If _ErrorHandler() Then On Local Error Goto Error_Function
233 Utils._SetCalledSub(
"SubForm.Controls
")
235 Dim ocControl As Variant, sParentShortcut As String, iControlCount As Integer
236 Dim oCounter As Variant, sControls() As Variant, i As Integer, bFound As Boolean, sIndex As String
239 Set ocControl = Nothing
240 iControlCount = DatabaseForm.getCount()
242 If IsMissing(pvIndex) Then
' No argument, return Collection pseudo-object
243 Set oCounter = New Collect
244 oCounter._CollType = COLLCONTROLS
245 oCounter._ParentType = OBJSUBFORM
246 oCounter._ParentName = _Shortcut
247 oCounter._Count = iControlCount
248 Set Controls = oCounter
252 If Not Utils._CheckArgument(pvIndex,
1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
254 ' Start building the ocControl object
255 ' Determine exact name
256 Set ocControl = New Control
257 ocControl._ParentType = CTLPARENTISSUBFORM
258 sParentShortcut = _Shortcut
259 sControls() = DatabaseForm.getElementNames()
261 Select Case VarType(pvIndex)
262 Case vbInteger, vbLong, vbSingle, vbDouble, vbCurrency, vbBigint, vbDecimal
263 If pvIndex
< 0 Or pvIndex
> iControlCount -
1 Then Goto Trace_Error_Index
264 ocControl._Name = sControls(pvIndex)
265 Case vbString
' Check control name validity (non case sensitive)
267 sIndex = UCase(Utils._Trim(pvIndex))
268 For i =
0 To iControlCount -
1
269 If UCase(sControls(i)) = sIndex Then
274 If bFound Then ocControl._Name = sControls(i) Else Goto Trace_NotFound
277 ocControl._Shortcut = sParentShortcut
& "!
" & Utils._Surround(ocControl._Name)
278 Set ocControl.ControlModel = DatabaseForm.getByName(ocControl._Name)
279 ocControl._ImplementationName = ocControl.ControlModel.getImplementationName()
280 ocControl._FormComponent = ParentComponent
281 If Utils._hasUNOProperty(ocControl.ControlModel,
"ClassId
") Then ocControl._ClassId = ocControl.ControlModel.ClassId
282 If ocControl._ClassId
> 0 And ocControl._ClassId
<> acHiddenControl Then
283 Set ocControl.ControlView = ParentComponent.CurrentController.getControl(ocControl.ControlModel)
286 ocControl._Initialize()
287 ocControl._DocEntry = _DocEntry
288 ocControl._DbEntry = _DbEntry
289 Set Controls = ocControl
292 Utils._ResetCalledSub(
"SubForm.Controls
")
295 TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(),
0,
1)
296 Set Controls = Nothing
299 TraceError(TRACEFATAL, ERRCONTROLNOTFOUND, Utils._CalledSub(),
0, , Array(pvIndex, _Name))
300 Set Controls = Nothing
303 TraceError(TRACEABORT, Err,
"SubForm.Controls
", Erl)
304 Set Controls = Nothing
306 End Function
' Controls V1.1
.0
308 REM -----------------------------------------------------------------------------------------------------------------------
309 Public Function getProperty(Optional ByVal pvProperty As Variant) As Variant
310 ' Return property value of psProperty property name
312 Utils._SetCalledSub(
"SubForm.getProperty
")
313 If IsMissing(pvProperty) Then Call _TraceArguments()
314 getProperty = _PropertyGet(pvProperty)
315 Utils._ResetCalledSub(
"SubForm.getProperty
")
317 End Function
' getProperty
319 REM -----------------------------------------------------------------------------------------------------------------------
320 Public Function hasProperty(ByVal Optional pvProperty As Variant) As Boolean
321 ' Return True if object has a valid property called pvProperty (case-insensitive comparison !)
323 If IsMissing(pvProperty) Then hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList()) Else hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList(), pvProperty)
326 End Function
' hasProperty
328 REM -----------------------------------------------------------------------------------------------------------------------
329 Public Function Refresh() As Boolean
330 ' Refresh data with its most recent value in the database in a form or subform
331 Utils._SetCalledSub(
"SubForm.Refresh
")
332 If _ErrorHandler() Then On Local Error Goto Error_Function
336 Set oSet = DatabaseForm.createResultSet()
337 If Not IsNull(oSet) Then
344 Utils._ResetCalledSub(
"SubForm.Refresh
")
347 TraceError(TRACEABORT, Err,
"SubForm.Refresh
", Erl)
349 End Function
' Refresh
351 REM -----------------------------------------------------------------------------------------------------------------------
352 Public Function Requery() As Boolean
353 ' Refresh data displayed in a form, subform, combobox or listbox
354 Utils._SetCalledSub(
"SubForm.Requery
")
355 If _ErrorHandler() Then On Local Error Goto Error_Function
358 DatabaseForm.reload()
362 Utils._ResetCalledSub(
"SubForm.Requery
")
365 TraceError(TRACEABORT, Err,
"SubForm.Requery
", Erl)
367 End Function
' Requery
369 REM -----------------------------------------------------------------------------------------------------------------------
370 Public Function setProperty(ByVal Optional psProperty As String, ByVal Optional pvValue As Variant) As Boolean
371 ' Return True if property setting OK
372 Utils._SetCalledSub(
"SubForm.setProperty
")
373 setProperty = _PropertySet(psProperty, pvValue)
374 Utils._ResetCalledSub(
"SubForm.setProperty
")
377 REM -----------------------------------------------------------------------------------------------------------------------
378 REM --- PRIVATE FUNCTIONS ---
379 REM -----------------------------------------------------------------------------------------------------------------------
380 REM -----------------------------------------------------------------------------------------------------------------------
381 Private Function _PropertiesList() As Variant
383 _PropertiesList = Array(
"AllowAdditions
",
"AllowDeletions
",
"AllowEdits
",
"CurrentRecord
" _
384 ,
"Filter
",
"FilterOn
",
"LinkChildFields
",
"LinkMasterFields
",
"Name
" _
385 ,
"ObjectType
",
"OrderBy
",
"OrderByOn
",
"Parent
",
"RecordSource
" _
386 )
' Recordset removed
388 End Function
' _PropertiesList
390 REM -----------------------------------------------------------------------------------------------------------------------
391 Private Function _PropertyGet(ByVal psProperty As String, ByVal Optional pvIndex As Variant) As Variant
392 ' Return property value of the psProperty property name
394 If _ErrorHandler() Then On Local Error Goto Error_Function
395 Utils._SetCalledSub(
"SubForm.get
" & psProperty)
396 Dim iArgNr As Integer
397 If Not IsMissing(pvIndex) Then
398 Select Case UCase(_A2B_.CalledSub)
399 Case UCase(
"getProperty
") : iArgNr =
3
400 Case UCase(
"SubForm.getProperty
") : iArgNr =
2
401 Case UCase(
"SubForm.get
" & psProperty) : iArgNr =
1
403 If Not Utils._CheckArgument(pvIndex, iArgNr, Utils._AddNumeric()) Then Goto Exit_Function
407 Dim oDatabase As Object, vBookmark As Variant, vEMPTY As Variant
408 _PropertyGet = vEMPTY
410 Select Case UCase(psProperty)
411 Case UCase(
"AllowAdditions
")
412 _PropertyGet = DatabaseForm.AllowInserts
413 Case UCase(
"AllowDeletions
")
414 _PropertyGet = DatabaseForm.AllowDeletes
415 Case UCase(
"AllowEdits
")
416 _PropertyGet = DatabaseForm.AllowUpdates
417 Case UCase(
"CurrentRecord
")
418 _PropertyGet = DatabaseForm.Row
419 Case UCase(
"Filter
")
420 _PropertyGet = DatabaseForm.Filter
421 Case UCase(
"FilterOn
")
422 _PropertyGet = DatabaseForm.ApplyFilter
423 Case UCase(
"LinkChildFields
")
424 If Utils._hasUNOProperty(DatabaseForm,
"DetailFields
") Then
425 If IsMissing(pvIndex) Then
426 _PropertyGet = DatabaseForm.DetailFields
428 If pvIndex
< 0 Or pvIndex
> UBound(DatabaseForm.DetailFields) Then Goto trace_Error_Index
429 _PropertyGet = DatabaseForm.DetailFields(pvIndex)
432 Case UCase(
"LinkMasterFields
")
433 If Utils._hasUNOProperty(DatabaseForm,
"MasterFields
") Then
434 If IsMissing(pvIndex) Then
435 _PropertyGet = DatabaseForm.MasterFields
437 If pvIndex
< 0 Or pvIndex
> UBound(DatabaseForm.MasterFields) Then Goto trace_Error_Index
438 _PropertyGet = DatabaseForm.MasterFields(pvIndex)
441 Case UCase(
"Name
")
443 Case UCase(
"ObjectType
")
445 Case UCase(
"OrderBy
")
446 _PropertyGet = _OrderBy
447 Case UCase(
"OrderByOn
")
448 If DatabaseForm.Order =
"" Then _PropertyGet = False Else _PropertyGet = True
449 Case UCase(
"Recordset
")
450 If DatabaseForm.Command =
"" Then Goto Trace_Error
' No underlying data ??
451 Set oObject = New Recordset
453 oObject._CommandType = .CommandType
454 oObject._Command = .Command
455 oObject._ParentName = _Name
456 oObject._ParentType = _Type
457 Set oDatabase = Application._CurrentDb(_DocEntry, _DbEntry)
458 Set oObject._ParentDatabase = oDatabase
459 Set oObject._ParentDatabase.Connection = .ActiveConnection
460 oObject._ForwardOnly = ( .ResultSetType = com.sun.star.sdbc.ResultSetType.FORWARD_ONLY )
461 oObject._PassThrough = ( .EscapeProcessing = False )
462 oObject._ReadOnly = ( .ResultSetConcurrency = com.sun.star.sdbc.ResultSetConcurrency.READ_ONLY )
463 Call oObject._Initialize()
466 .RecordsetMax = .RecordsetMax +
1
467 oObject._Name = Format(.RecordsetMax,
"0000000")
468 .RecordsetsColl.Add(oObject, UCase(oObject._Name))
470 Set _PropertyGet = oObject
471 Case UCase(
"RecordSource
")
472 _PropertyGet = DatabaseForm.ActiveCommand
478 Utils._ResetCalledSub(
"SubForm.get
" & psProperty)
481 TraceError(TRACEWARNING, ERRPROPERTY, Utils._CalledSub(),
0,
1, psProperty)
482 _PropertyGet = vEMPTY
485 TraceError(TRACEFATAL, ERRINDEXVALUE, Utils._CalledSub(),
0,
1, psProperty)
486 _PropertyGet = vEMPTY
489 TraceError(TRACEABORT, Err,
"SubForm._PropertyGet
", Erl)
490 _PropertyGet = vEMPTY
492 End Function
' _PropertyGet
494 REM -----------------------------------------------------------------------------------------------------------------------
495 Private Function _PropertySet(ByVal psProperty As String, ByVal pvValue As Variant) As Boolean
497 Utils._SetCalledSub(
"SubForm.set
" & psProperty)
498 If _ErrorHandler() Then On Local Error Goto Error_Function
502 Dim iArgNr As Integer
504 If _IsLeft(_A2B_.CalledSub,
"SubForm.
") Then iArgNr =
1 Else iArgNr =
2
505 Select Case UCase(psProperty)
506 Case UCase(
"AllowAdditions
")
507 If Not Utils._CheckArgument(pvValue, iArgNr, vbBoolean, , False) Then Goto Trace_Error_Value
508 DatabaseForm.AllowInserts = pvValue
509 DatabaseForm.reload()
510 Case UCase(
"AllowDeletions
")
511 If Not Utils._CheckArgument(pvValue,iArgNr, vbBoolean, , False) Then Goto Trace_Error_Value
512 DatabaseForm.AllowDeletes = pvValue
513 DatabaseForm.reload()
514 Case UCase(
"AllowEdits
")
515 If Not Utils._CheckArgument(pvValue, iArgNr, vbBoolean, , False) Then Goto Trace_Error_Value
516 DatabaseForm.AllowUpdates = pvValue
517 DatabaseForm.reload()
518 Case UCase(
"CurrentRecord
")
519 If Not Utils._CheckArgument(pvValue, iArgNr, Utils._AddNumeric(), , False) Then Goto Trace_Error_Value
520 DatabaseForm.absolute(pvValue)
521 Case UCase(
"Filter
")
522 If Not Utils._CheckArgument(pvValue, iArgNr, vbString, , False) Then Goto Trace_Error_Value
523 DatabaseForm.Filter = Application._CurrentDb(_DocEntry, _DbEntry)._ReplaceSquareBrackets(pvValue)
524 Case UCase(
"FilterOn
")
525 If Not Utils._CheckArgument(pvValue, iArgNr, vbBoolean, , False) Then Goto Trace_Error_Value
526 DatabaseForm.ApplyFilter = pvValue
527 DatabaseForm.reload()
528 Case UCase(
"OrderBy
")
529 If Not Utils._CheckArgument(pvValue, iArgNr, vbString, , False) Then Goto Trace_Error_Value
530 _OrderBy = Application._CurrentDb(_DocEntry, _DbEntry)._ReplaceSquareBrackets(pvValue)
531 Case UCase(
"OrderByOn
")
532 If Not Utils._CheckArgument(pvValue, iArgNr, vbBoolean, , False) Then Goto Trace_Error_Value
533 If pvValue Then DatabaseForm.Order = _OrderBy Else DatabaseForm.Order =
""
534 DatabaseForm.reload()
535 Case UCase(
"RecordSource
")
536 If Not Utils._CheckArgument(pvValue, iArgNr, vbString, , False) Then Goto Trace_Error_Value
537 DatabaseForm.Command = Application._CurrentDb(_DocEntry, _DbEntry)._ReplaceSquareBrackets(pvValue)
538 DatabaseForm.CommandType = com.sun.star.sdb.CommandType.COMMAND
539 DatabaseForm.Filter =
""
540 DatabaseForm.reload()
546 Utils._ResetCalledSub(
"SubForm.set
" & psProperty)
549 TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(),
0,
1, psProperty)
553 TraceError(TRACEFATAL, ERRPROPERTYVALUE, Utils._CalledSub(),
0,
1, Array(pvValue, psProperty))
557 TraceError(TRACEABORT, Err,
"SubForm._PropertySet
", Erl)
560 End Function
' _PropertySet