[Solved] [Base] Field Macro

Creating a macro - Writing a Script - Using the API

[Solved] [Base] Field Macro

Postby 203mkj » Tue Aug 31, 2010 9:20 pm

I'm using Base for my companies database for their technology and keeping notes on it. Something I've done is I have a map of the floor plan and I've placed an object over top each work station and turned it into a button to open a form. Now the macro reads the "additional information" area of the button and filters a field which brings up the work station Id. Now this is where I get stuck. I want to be able to create a button that when it is clicked will read the information from that field and open another form.

For example: I click on a workstation on my map. It brings up the station ID, with four buttons on it. I click on the button and it displays all of the computers connected to that station filtered by the station ID. I hope this makes sense and could really use some help.

Thanks.
Last edited by Hagar Delest on Thu Sep 02, 2010 12:53 pm, edited 1 time in total.
Reason: tagged [Solved].
OpenOffice 3.2 on Windows XP
203mkj
 
Posts: 2
Joined: Tue Aug 31, 2010 9:12 pm

Re: Field Macro

Postby littlefish » Wed Sep 01, 2010 1:58 am

Let me see if I understand your question.
1. You have a layoutform that has a button1 with its tag property holding a workstationid
2. Button 1 opens form2 and sets its filter = workstationid. form2 has 4 additional buttons, where button2 is titled ConnectedComputers.

You want to have button2 open form3 based on a table of connections and set its filter = workstationid from the workstation id in form2 bound data?
OpenOffice 3.2 on Windows 7
littlefish
 
Posts: 3
Joined: Wed Sep 01, 2010 12:37 am

Re: [Base] Field Macro

Postby littlefish » Wed Sep 01, 2010 1:30 pm

If my assumptions are correct above, then the code for button1 would look like:

Code: Select all   Expand viewCollapse view
sub ComputerButton (oEvent)
   Dim sComputerId as string
   Dim oDatabaseForm
   Dim oConnectionWrapper
   Dim oDocumentContainer
   Dim args(1) As New com.sun.star.beans.PropertyValue
   Dim oTextDocument
   Dim oDatabaseFormForm2
   
   'get the computer id from button's tag
   sComputerId = oEvent.Source.Model.tag

   'set variables needed to open text document
   oDatabaseForm = oEvent.Source.Model.Parent 'com.sun.star.comp.forms.ODatabaseForm, this has the design properties
   oConnectionWrapper =  oDatabaseForm.ActiveConnection 'com.sun.star.sdbc.drivers.OConnectionWrapper
   oDocumentContainer = oConnectionWrapper.Parent.DatabaseDocument.FormDocuments 'com.sun.star.comp.dba.ODocumentContainer

   'open text document
   args(0).Name = "ActiveConnection"
   args(0).Value = oConnectionWrapper
   args(1).Name = "OpenMode"
   args(1).Value = "open"
   oTextDocument = oDocumentContainer.loadComponentFromURL("Form2","_blank",0,args()) ' SwXTextDocument

   'this gets form2 and sets the filter
   oDatabaseFormForm2 = oTextDocument.getDrawPage.forms.GetByName("Form") 'com.sun.star.comp.forms.ODatabaseForm
   oDatabaseFormForm2.Filter = "( ""computer"" = '" & sComputerId & "' )"
   oDatabaseFormForm2.ApplyFilter = True
   oDatabaseFormForm2.Reload

end sub


then button2 code would be

Code: Select all   Expand viewCollapse view
sub ComputerButton2 (oEvent)
   Dim oDatabaseForm
   Dim oConnectionWrapper
   Dim oDocumentContainer
   Dim args(1) As New com.sun.star.beans.PropertyValue
   Dim oTextDocument
   Dim oDatabaseFormForm3
   dim sComputerId as string
   
   'set variables needed to open text document
   oDatabaseForm = oEvent.Source.Model.Parent 'com.sun.star.comp.forms.ODatabaseForm, this has the design properties
   oConnectionWrapper =  oDatabaseForm.ActiveConnection 'com.sun.star.sdbc.drivers.OConnectionWrapper
   oDocumentContainer = oConnectionWrapper.Parent.DatabaseDocument.FormDocuments 'com.sun.star.comp.dba.ODocumentContainer

   'this gets the filter criteria from the current form's data source
   'if you are pulling an integer, then use getinteger(columnindex)
   '2 represents the column index of the underlying forms table or query starting with 1
   sComputerId = oDatabaseForm.getstring(2)
   
   'open text document
   args(0).Name = "ActiveConnection"
   args(0).Value = oConnectionWrapper
   args(1).Name = "OpenMode"
   args(1).Value = "open"
   oTextDocument = oDocumentContainer.loadComponentFromURL("Form3","_blank",0,args()) ' SwXTextDocument

   'this gets form3 and sets the filter
   oDatabaseFormForm3 = oTextDocument.getDrawPage.forms.GetByName("Form") 'com.sun.star.comp.forms.ODatabaseForm
   oDatabaseFormForm3.Filter = "( ""computer"" = '" & sComputerId & "' )"
   oDatabaseFormForm3.ApplyFilter = True
   oDatabaseFormForm3.Reload

end sub


let me know if i got it right
OpenOffice 3.2 on Windows 7
littlefish
 
Posts: 3
Joined: Wed Sep 01, 2010 12:37 am

Re: [Base] Field Macro

Postby 203mkj » Wed Sep 01, 2010 9:11 pm

I had the first button. But on the second one I was having trouble figuring out how to read the data from the field.

This is my first button code:
Code: Select all   Expand viewCollapse view
Sub Get_Button_Name ( GBN as object)
Dim sFrmCtrl as object
Dim sControl As Object
sControl = GBN.Source.Model
sFormName = "UserForm"
OpenForm( getFormsTC, getConnectionTC, sFormName )
sFrmCtrl = ThisComponent.Drawpage.Forms.getByIndex(0)
'sFrmCtrl = ThisComponent.Drawpage.Forms.getByName(sFormName)
'MsgBox (sFrmCtrl.Name)
sFrmCtrl.Filter = "(" & Chr(34) & "Ports" & Chr(34) & "." & Chr(34) & "EthPort" & Chr(34) & " = '" & sControl.tag & "')"
'MsgBox (sFrmCtrl.Filter)
sFrmCtrl.ApplyFilter = True
sFrmCtrl.Reload()


I took your code on the second button and modified it and it works perfectly! THANK YOU!

Code: Select all   Expand viewCollapse view
sub Comp (oEvent)
   Dim oDatabaseForm
   Dim oConnectionWrapper
   Dim oDocumentContainer
   Dim args(1) As New com.sun.star.beans.PropertyValue
   Dim oTextDocument
   Dim sDatabaseFormForm3ctrl as object
   dim sComputerId as string
   
   'set variables needed to open text document
   oDatabaseForm = oEvent.Source.Model.Parent 'com.sun.star.comp.forms.ODatabaseForm, this has the design properties
   oConnectionWrapper =  oDatabaseForm.ActiveConnection 'com.sun.star.sdbc.drivers.OConnectionWrapper
   oDocumentContainer = oConnectionWrapper.Parent.DatabaseDocument.FormDocuments 'com.sun.star.comp.dba.ODocumentContainer

   'this gets the filter criteria from the current form's data source
   'if you are pulling an integer, then use getinteger(columnindex)
   '2 represents the column index of the underlying forms table or query starting with 1
   sComputerId = oDatabaseForm.getstring(1)
   'MsgBox("Value is = " & sComputerID)
   'open text document
   args(0).Name = "ActiveConnection"
   args(0).Value = oConnectionWrapper
   args(1).Name = "OpenMode"
   args(1).Value = "open"
   oTextDocument = oDocumentContainer.loadComponentFromURL("CompForm","_blank",0,args()) ' SwXTextDocument

   'this gets form3 and sets the filter
   sDatabaseFormForm3 = "CompForm"
   
   'MsgBox("Form is" & sDatabaseFormFrom3)
   
   OpenForm( getFormsTC, getConnectionTC, sDatabaseFormForm3 )
' This is where the fun starts. The next statement works retrieving the name of the form document
   sDatabaseFormForm3ctrl = ThisComponent.Drawpage.Forms.getByIndex(0)
   sDatabaseFormForm3ctrl.Filter = "(" & Chr(34) & "Computers" & Chr(34) & "." & Chr(34) & "EthPort" & Chr(34) & " = '" & sComputerId & "')"
   sDatabaseFormForm3ctrl.ApplyFilter = True
   sDatabaseFormForm3ctrl.Reload

end sub
OpenOffice 3.2 on Windows XP
203mkj
 
Posts: 2
Joined: Tue Aug 31, 2010 9:12 pm

Re: [Base] Field Macro

Postby littlefish » Wed Sep 01, 2010 11:28 pm

No problem. Just marking it solved.
OpenOffice 3.2 on Windows 7
littlefish
 
Posts: 3
Joined: Wed Sep 01, 2010 12:37 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 9 guests