Transfer a data set from openoffice base to calc - openoffice.org

After I did a query in openoffice-base over a customized form I want to transfer a selected set of data into a template openoffice-calc table. I know I can access the data set in openoffice-calc via pressing the Data Source (F4) button but then I only get access over the query. The best solution would be after the database query over a form a button event is required to open a openoffice-calc table from the template and insert the data from the data set.

First go to Tools -> Macros -> Organize Macros -> LibreOffice Basic and add this code. Change the path of the template file.
Sub Copy_Record_To_Calc(oEvent)
Dim oForm
Dim templatePath As String
Dim oServiceManager As Object, oDesktop As Object
Dim oFileProperties As Object
Dim oDoc As Object, oSheet As Object, oCell As Object
Dim column As Integer
oForm = oEvent.Source.getModel().getParent()
If oForm.isAfterLast() Then
Print "Hey, you are after the last element."
Exit Sub
ElseIf oForm.isBeforeFirst() Then
Print "Hey, you are before the first element."
Exit Sub
End If
templatePath = "file:///C:/Users/JimStandard/Desktop/Untitled 2.ots"
Set oServiceManager = CreateObject("com.sun.star.ServiceManager")
Set oDesktop = oServiceManager.createInstance("com.sun.star.frame.Desktop")
Set oFileProperties(0) = new com.sun.star.beans.PropertyValue
oFileProperties(0).Name = "AsTemplate"
oFileProperties(0).Value = True
Set oDoc = oDesktop.loadComponentFromURL( _
templatePath, "_blank", 0, Array(oFileProperties))
oSheet = oDoc.Sheets(0)
For column = 1 to 2
oCell = oSheet.getCellByPosition(column - 1, 0)
oCell.String = oForm.getString(column)
Next column
End Sub
Then in form design mode, right-click on the button and choose Control. In the Events tab, click the three dots next to Execute action. Click Macro... and find the Copy_Record_To_Calc macro that you added.
Now turn design mode off. Go to a record and click the button. It will open the Calc template and copy the first two columns of the current record into column A and B of the spreadsheet.
See also:
Section 4.2.1 of Andrew Pitonyak's Base Macros (PDF)
ResultSet documentation
This thread gives an example of using a Calc template.

Related

Custom wireshark disector shows value but fieldname is not visible using lua

I am testing some network packets of my Organisation's product. We already have custom plugins. I am trying to add some some more fields into those existing plugins (like conversion of 2 byte code to a string and assign it to a field)
Thankyou in advance for reading my query.
--edit
Wireshark version : 2.4.5 (organization's plugins dont work on latest wireshark application)
--edit
Problem statement:
I am able to add field and show value, but fieldname is not displayed as defined.
I cannot share the entire .lua file but i will try to explain What i did:
Below is the image where I have a field aprint.type. this is a two byte field. In .lua file, for display purpose it is appended with corresponding description using a custom function int_to_enum.
I want to add one more proto field aprint.typetext which will show the text.
What I did:
Added a protofield f_apr_msg_type_txt = ProtoField.string("aprint.typetxt","aprint_type_text") (Tried f_apr_msg_type_txt = ProtoField.string("aprint.typetxt","aprint_type_text",FT_STRING) also)
Below the code where subtree aprint.type is shown, added my required field as subtree:add(f_apr_msg_type_txt, msg_type_string) (Below is image of code extract)
I am able to see the text but field Name is shown as Wireshark Lua text (_ws.lua.text)
Normally displaying strings based on numeric values is accomplished by a value string lookup, so you'd have something like so:
local aprint_type_vals = {
[1] = "Foo",
[2] = "Bar",
[9] = "State alarm"
}
f_apr_msg_type = ProtoField.uint16("aprint.type", "Type", base.DEC, aprint_type_vals)
f_apr_msg_type_txt = ProtoField.string("aprint.typetxt","aprint_type_text", base.ASCII)
... then
local msg_type = tvb(offset, 2):le_uint()
subtree:add_le(f_apr_msg_type, tvb(offset, 2))
subtree:add(f_apr_msg_type_txt, tvb(offset, 2), (aprint_type_vals[msg_type] or "Unknown"))
--[[
Alternatively:
subtree:add(f_apr_msg_type_txt, tvb(offset, 2)):set_text("aprint_type_text: " .. (aprint_type_vals[msg_type] or "Unknown"))
--]]
I'm also not sure why you need the extra field with only the text when the text is already displayed with the existing field, but that's basically how you'd do it.

Call the name of a Texbox with number changing in Visual Basic 6

I'm use Visual Basic 6 to create a table with many Textbox which named txtNo1, txtNo2, txtNo3,...
I want to use the "For...Next..." loop to assign a content to these Textbox.
How can I call all these Textbox in the simplest way?
For i = 1 to 100
txtNo (......) .txt = "ABC"
Next i
Instead of using unique textboxes, each with a unique name, you should use a (textbox) control array:
Place the 1st textbox on the form, name it 'txtNo'
Copy it and paste it onto the form
VB will ask you "There's already a control named 'txtNo'. Would you like to create a control array?". Answer "Yes"
Paste as the textbox as many times as you need it
Then your code looks like
' Control arrays typically start at index 0
For i = 0 to 100
txtNo(i) .txt = "ABC"
Next i
Jim Mack's solution works as well, code for it:
' Assuming your form is named 'Form1'
For each ctrl in Form1.Controls
If TypeOf ctrl Is Textbox
For i = 1 To 100
If ctrl.Name = "txtNo" & CStr(i) Then
ctrl.Text = "ABC"
End If
End If
End If
It's a bit more complex, but therefore more flexible as works with multiple control types (in one loop).
If you need an easiest way to create your textboxes as a table, you can Load the controls at runtime. You have to add only the first TextBox control to your form, set the name to "txtNo", and Index to 0 in the Properties window.
In your code, call Load() to create additional controls, and you can set the Top/Left and other properties
For i = 1 To 100
Load txtNo(i)
txtNo(i).Top = txtNo(i - 1).Top + txtNo(i - 1).Height + 150
txtNo(i).Left = txtNo(i - 1).Left
txtNo(i).Text = "Textbox " & i
txtNo(i).Visible = True
Next i
If you need again to change any control property, from your list of controls, you can iterate only over your control list, instead of all controls of your Form
For i = txtNo.LBound() To txtNo.UBound()
Form1.Controls("txtNo")(i).Text = "New text " & i
Next i

Breaking Links to Excel for PowerPoint Charts

I wrote a code to break links to the source excel file for my powerpoint deck, the macro works well except for 2 charts. Both the charts are on the same slide (which is not uncommon) and are line charts. The charts need to be manually updated but the data resides in a excel file only. Not sure what am I missing. This is the code that I wrote
Sub SavePPT()
Dim objPP As Object
Dim objPPFile As Object
Dim sld As Object
Dim shp As Object
Dim shp1 As Chart
Dim newshp As Shape
Dim pptChart As Object
Set objPP = CreateObject("PowerPoint.Application")
objPP.Visible = True
Set objPPFile = objPP.ActivePresentation
objPPFile.Save
Application.EnableEvents = False
For Each sld In objPPFile.Slides
For Each shp In sld.Shapes
If shp.HasChart Then
shp.LinkFormat.BreakLink
On Error GoTo 0
End If
Next
Next
Application.EnableEvents = False
For Each sld In objPPFile.Slides
For Each shp In sld.Shapes
If shp.Type = msoLinkedOLEObject Or shp.Type = msoEmbeddedOLEObject Then
shp.LinkFormat.BreakLink
On Error GoTo 0
End If
Next
Next
objPPFile.SaveAs ("Location" _ & Format(Now(), "MM-DD-YYYY") & ".pptx")
objPPFile.Close
objPP.Quit
Set pptChart = Nothing
Set objPPFile = Nothing
Set objPP = Nothing
End Sub
The chart might be in a placeholder, in which case none of your code will act upon it. If the shape's .Type = msoPlaceholder (ie, 14), check the shape's .PlaceholderFormat.ContainedType property to see if it's a linkedOleobject or .HasChart etc.
BTW, an msoEmbeddedOLEObject won't have a .LinkFormat object to call on; I suspect you have some error handling code that's obscuring an error there. In any case, I'd limit that check to just msoLinkedOLEObject.
Thanks for you help. I realized it later that those 2 slides have a lot of text boxes on them and when I consolidate some of those textboxes the issue was resolved.

Lotusscript - Printing a Notes-Document with NotesUIDocument.Print does not work as documented

I want to print Notes-documents directly to an pdf-printer. The documents are selected in a view. I do not want to open the printer dialog form.
Using the "NotesUIView.Print"- method works in principle, however, the generated pdf-documents sometimes look not exactly like the Notes-documents (especially regarding tables).
Therefore I tried to use the "NotesUIDocument.Print" - method:
Option Public
Option Explicit
Const pdfAppName = "PDF-XChange Standard"
Dim dc As NotesDocumentCollection
Dim curDoc As NotesDocument
Dim uidoc As NotesUIDocument
Dim workspace As New NotesUIWorkspace
...
Set dc = curDB.UnprocessedDocuments
...
Set curdoc = dc.GetFirstDocument
Call workspace.EditDocument(False,curDoc)
Set uidoc = workspace.Currentdocument
Call uidoc.Print(1,0,0,False,pdfAppName)
...
Dispite the first parameter in "uidoc.print" is set to "1" the printer dialog form opens. In the printer dialog form the printer "PDF-XChange Standard" is selected correctly. Selecting the "OK"-Button prints the document correctly.
Many thanks in advance for hints.

VB6 populate a list box using adodb recordset

I had a form which originally used Listview control but I need to change it into Listbox control. Now here's the original code which use for listview. I'm trying to change it for populate listbox using adodb recordset but keep getting errors. lv1 is the listbox1; lv2 is the listbox2. Listbox doesn't have listitem.
Private Sub PopulateListView()
Dim cnPop As ADODB.Connection
Dim rsPop As ADODB.Recordset
Dim lst As ListItem
Dim lngRecs As Long
On Error GoTo ErrPopulate
Set cnPop = New ADODB.Connection
cnPop.CursorLocation = adUseClient
cnPop.Open gcnORA
Set rsPop = New ADODB.Recordset
rsPop.Open sSQL, cnPop, adOpenDynamic, adLockReadOnly
lv1.ListItems.Clear
Do While rsPop.EOF = False
Set lst = lv1.ListItems.Add(, , rsPop!Customer_Number)
lst.SubItems(1) = rsPop!Customer_Name
rsPop.MoveNext
Loop
If rsPop.RecordCount > 0 Then
SelectButtons True
End If
With lblCount
.Caption = Format((rsPop.RecordCount), "#,##0") & IIf((rsPop.RecordCount) <= 1, " Customer", " Customers") & " found"
.Refresh
End With
rsPop.Close
cnPop.Close
Set rsPop = Nothing
Set cnPop = Nothing
Exit Sub
ErrPopulate:
MsgBox Err.Description, vbCritical, "Populate Error"
End Sub
A listview can have multiple columns, you apparently had at least two columns in your previous listview: Customer Number and Customer Name.
A listbox only has one column. You'll need to decide how to display/add your two columns of data to the listbox. Don't be confused by the columns property of the listbox, when set to multiple columns, the control still only has a single column of data - it simply snakes and scrolls horizontally instead of scrolling vertically.
Adding an item to the listbox:
lv1.Additem rsPop!Customer_Name
Listbox documentation: VB6 Listbox

Resources