Tenesta SFDocuments.Base

Tenesta Base inneheld ei rad metodar og eigenskapar for å forenkla administreringa og hanfsaminga av LibreOffice Base-dokument.

Denne tenesta er nært knytt til tenesta ;Document, som inneheld generiske metodar for handsaming av LibreOffice-dokument, inkludert Base-dokument. Difor utvidar tenesta Base Document-tenesta og inneheld fleire metodar som er spesifikke for Base-dokument, slik at brukarane kan:

note

Denne tenesta er tilgjengeleg frå LibreOffice 7.2 og høgare.


tip

Sjå tenesta Document for å læra meir om metodane og eigenskapane som kan brukast for å administrera LibreOffice-dokument.


Oppkall av tenester

I Basic

Tenesta Base kan kallast opp på ulike måtar. Kodesnutten nedanfor brukar metoden CreateBaseDocument i tenesta UI til å laga ei ny Base-fil.

Note that in all examples the object oDoc is an instance of the Base service.


    Dim ui As Object, oDoc As Object
    Set ui = CreateScriptService("UI")
    Set oDoc = ui.CreateBaseDocument("C:\Documents\MyFile.odb")
  

The Base service can also be instantiated while opening an existing Base file, as shown below:


    Set oDoc = ui.OpenBaseDocument("C:\Documents\MyFile.odb")
  

If a Base document is already open, it is possible to instantiate the Base service directly:


    Dim oDoc As Object
    Set oDoc = CreateScriptService("SFDocuments.Document", "MyFile.odb")
  
I Python

The examples above can be translated to Python as follows:


    from scriptforge import CreateScriptService
    ui = CreateScriptService("UI")
    doc = ui.CreateBaseDocument(r"C:\Documents\MyFile.odb")
  

    doc = ui.OpenBaseDocument(r"C:\Documents\MyFile.odb")
  

    doc = CreateScriptService("SFDocuments.Document", "MyFile.odb")
  
note

The use of the "SFDocuments." substring in the previous example is optional.


List of Methods in the Base Service

FormDocuments
Forms

GetDatabase
IsLoaded

OpenFormDocument


FormDocuments

Returns an array with the full names (path/name) of all form documents in the Base document as an zero-based Array of strings.

Syntaks:

svc.FormDocuments(): str[0..*]

Eksempel:

The code snippet below prints the names of all form documents in the current Base document.

I Basic

    Dim oDoc as Object, myForms as Object, formName as String
    Set oDoc = CreateScriptService("Document", ThisDataBaseDocument)
    Set myForms = oDoc.FormDocuments()
    For Each formName In myForms
        MsgBox formName
    Next formName
  
I Python

    bas = CreateScriptService("Basic")
    doc = CreateScriptService("Document", bas.ThisDataBaseDocument)
    myForms = oDoc.FormDocuments()
    for formName in myForms:
        bas.MsgBox(formName)
  
tip

To learn more about form documents, refer to the Form service help page.


Forms

Depending on the parameters provided this method will return:

Syntaks:

svc.Forms(formdocument: str): str[0..*]

svc.Forms(formdocument: str, form: str = ''): svc

svc.Forms(formdocument: str, form: int): svc

Parametrar:

formdocument: The name of a valid form document as a case-sensitive string.

form: The name or index number of the form stored in the form document. If this argument is absent, the method will return a list with the names of all forms available in the form document.

note

Although it is possible to use index numbers to refer to forms, this is only recommended when there is just one form in the form document. If there are two or more forms, it is preferable to use the form name instead.


Eksempel:

The first line of the example below returns a list of all forms in the form document "myFormDocument". The second line returns an instance of the Form service representing the form "myForm".

I Basic

    Dim formsList as Object : formsList = oDoc.Forms("myFormDocument")
    Dim oForm as Object : oForm = oDoc.Forms("myFormDocument", "myForm")
  
I Python

    formsList = doc.Forms("myFormDocument")
    form = doc.Forms("myFormDocument", "myForm")
  

GetDatabase

Returns an instance of the Database service that allows the execution of SQL commands on the database defined and/or stored in the current Base document

Syntaks:

svc.GetDatabase(user: str = '', password: str = ''): svc

Parametrar:

user, password: Optional login parameters as strings. The default value for both parameters is an empty string "".

Eksempel:

I Basic

    Dim myDoc As Object, myDatabase As Object, ui As Object
    Set ui = CreateScriptService("UI")
    Set myDoc = ui.OpenBaseDocument("C:\Documents\myDb.odb")
    ' User and password are supplied below, if needed
    Set myDatabase = myDoc.GetDatabase()
    '   ... Run queries, SQL statements, ...
    myDatabase.CloseDatabase()
    myDoc.CloseDocument()
  
I Python

    ui = CreateScriptService("UI")
    myDoc = ui.OpenBaseDocument(r"C:\Documents\myDb.odb")
    myDatabase = myDoc.GetDatabase()
    '   ... Run queries, SQL statements, ...
    myDatabase.CloseDatabase()
    myDoc.CloseDocument()
  

IsLoaded

Returns True if the specified FormDocument is currently open.

Syntaks:

svc.IsLoaded(formdocument: str): bool

Parametrar:

formdocument: The name of a FormDocument to be checked, as a case-sensitive string.

Eksempel:

I Basic

    If Not oDoc.IsLoaded("myFormDocument") Then
        oDoc.OpenFormDocument("myFormDocument")
    End If
  
I Python

    if not doc.IsLoaded("myFormDocument"):
        doc.OpenFormDocument("myFormDocument")
  

OpenFormDocument

Opens the specified FormDocument either in normal or in design mode.

If the form document is already open, it is activated without changing its mode. The method returns True if the form document could be opened.

Syntaks:

svc.OpenFormDocument(formdocument: str, designmode: bool = False): bool

Parametrar:

formDocument: The name of the FormDocument to be opened, as a case-sensitive string.

designmode: If this argument is True the FormDocument will be opened in design mode.

Eksempel:

I Basic

Most form documents are stored in the root of the Base document and they can be opened simply using their names, as in the example below:


    oDoc.OpenFormDocument("FormDokumentetMitt")
  

If form documents are organized in folders, it becomes necessary to include the folder name to specify the form document to be opened, as illustrated in the following example:


    oDoc.OpenFormDocument("miMappe/FormDokumentetMitt")
  
I Python

    doc.OpenFormDocument("myFormDocument")
  

    doc.OpenFormDocument("myFolder/myFormDocument")
  
warning

Alle Basic-rutinane og -identifikatorane i ScriptForge som vert innleidde med understrek «_» er reserverte for internt bruk. Dei er ikkje tenkt brukte i Basic-makroar.