Creating macros in Base
Posted: Thu Jan 16, 2014 4:37 am
Hi,
I have been trawling the forum for macros to do functions that in need.
I have found some code but when I have inserted it into my macro library, it has deleted everything else that was all ready there.
I read a document I found called "Getting started with macros" and it may as well have been in Klingon for all the value I was able to get from it.
This is what I have done.
Open the DB > tools > macros > organize macros > open office basic.
At this point I highlighted the library (standard) so that 'new' became available.
I clicked 'new' which opened up the macros window and I copied whatever piece of code I had found.
The tricky bit then was there was no 'save' button just a 'save as'.
When I clicked 'save as' I got my new macro but all the others were gone.
Yes, I was working on a saved copy of the DB so could go back to what I had.
Any suggestions about where I am going wrong?
One of the macros I want is a macro on a push button that opens a new/clean record in a particular form.
I found this code and was inserting it in the create macro window. I assumed I just need to copy and insert the whole piece of code. I did change the line with FormName in it to the form I need opened.
Many thanks in advance.
Jenny
I have been trawling the forum for macros to do functions that in need.
I have found some code but when I have inserted it into my macro library, it has deleted everything else that was all ready there.
I read a document I found called "Getting started with macros" and it may as well have been in Klingon for all the value I was able to get from it.
This is what I have done.
Open the DB > tools > macros > organize macros > open office basic.
At this point I highlighted the library (standard) so that 'new' became available.
I clicked 'new' which opened up the macros window and I copied whatever piece of code I had found.
The tricky bit then was there was no 'save' button just a 'save as'.
When I clicked 'save as' I got my new macro but all the others were gone.
Yes, I was working on a saved copy of the DB so could go back to what I had.

Any suggestions about where I am going wrong?
One of the macros I want is a macro on a push button that opens a new/clean record in a particular form.
I found this code and was inserting it in the create macro window. I assumed I just need to copy and insert the whole piece of code. I did change the line with FormName in it to the form I need opened.
Many thanks in advance.
Jenny
Code: Select all
Sub AutoExec
Dim LastFrame As Object
Dim NumFrames As Integer
Static FormDocs As Object
Dim DBDoc As Object
Dim ImpName As String
Dim DataSource As Object
Dim Conn As Object
Dim Args(0) As New com.sun.star.beans.PropertyValue
Dim FormName As String
Dim FormDoc As Object
Dim oFormulario as Object: Dim oFeld as Object
On Error Goto HandleError
FormName= "frm_CustomerDetails":
ImpName="com.sun.star.comp.dba.ODatabaseDocument"
NumFrames=StarDesktop.Frames.Count
LastFrame=StarDesktop.Frames.getByIndex(NumFrames-1)
If LastFrame.Frames.Count>1 Then:
Exit Sub
End If
If Not (LastFrame.Controller.Model.ImplementationName=ImpName) Then
Exit Sub
End If
DataSource=LastFrame.Controller.DataSource
DBDoc=DataSource.DatabaseDocument
FormDocs=DBDoc.FormDocuments
Conn=DataSource.getConnection("","")
Args(0).Name="ActiveConnection" : Args(0).Value=Conn
if FormDocs.hasByName(FormName) Then:
FormDoc=FormDocs.loadComponentFromURL(FormName,"_self",0,Args() )
FormDoc.CurrentController.Frame.ContainerWindow.setFocus()
End If
With FormDoc.getCurrentController().getFrame().getContainerWindow()
.setPosSize( 100, 200 , , , com.sun.star.awt.PosSize.POS)
.setPosSize( , , 1600, 842 , com.sun.star.awt.PosSize.SIZE )
End With
HandleError:
If Err<>0 Then
Exit Sub
End If
End Sub