Base - automatically running a macro on form opening

classic Classic list List threaded Threaded
5 messages Options
Egbert Eissing Egbert Eissing
Reply | Threaded
Open this post in threaded view
|

Base - automatically running a macro on form opening

I need to fire up a macro automatically when I open a form, or when I move to the next record.
There is obviously no form event that allows me to do that. I have placed a simple macro, containing nothing but a message box into all relevant event slots, to see whether any one of them will fire. But none did. This appears to be strange to me, lacking such an important function.I am now using a button to run my macro, but this is unsatisfactory.
Does anyone have an idea how I can accomplish my task?Thanks for any help.Egbert

--
To unsubscribe e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted
Alex Thurgood Alex Thurgood
Reply | Threaded
Open this post in threaded view
|

Re: Base - automatically running a macro on form opening

Le 04/02/2016 04:59, Egbert Eissing a écrit :

Hi Egbert,



> I need to fire up a macro automatically when I open a form, or when I move to the next record.
> There is obviously no form event that allows me to do that. I have placed a simple macro, containing nothing but a message box into all relevant event slots, to see whether any one of them will fire. But none did. This appears to be strange to me, lacking such an important function.I am now using a button to run my macro, but this is unsatisfactory.
> Does anyone have an idea how I can accomplish my task?Thanks for any help.Egbert
>


If your are running LibreOffice on Mac, it is currently broken
functionality :

http://bugs.documentfoundation.org/show_bug.cgi?id=95191

Alex




--
To unsubscribe e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted
Noel Noel
Reply | Threaded
Open this post in threaded view
|

Re: Base - automatically running a macro on form opening

In reply to this post by Egbert Eissing
Hi Egbert,

If you are running on a Windows machine, I have found ways to do what you
were asking and I could make some suggestions if that would help.

Noel
--
Noel Lodge
[hidden email]

On 4 February 2016 at 14:59, Egbert Eissing <[hidden email]> wrote:

> I need to fire up a macro automatically when I open a form, or when I move
> to the next record.
> There is obviously no form event that allows me to do that. I have placed
> a simple macro, containing nothing but a message box into all relevant
> event slots, to see whether any one of them will fire. But none did. This
> appears to be strange to me, lacking such an important function.I am now
> using a button to run my macro, but this is unsatisfactory.
> Does anyone have an idea how I can accomplish my task?Thanks for any
> help.Egbert
>
> --
> To unsubscribe e-mail to: [hidden email]
> Problems?
> http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
> Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
> List archive: http://listarchives.libreoffice.org/global/users/
> All messages sent to this list will be publicly archived and cannot be
> deleted
>

--
To unsubscribe e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted
Andrew Douglas Pitonyak Andrew Douglas Pitonyak
Reply | Threaded
Open this post in threaded view
|

Re: Base - automatically running a macro on form opening

Well, for sure you can fire a macro when a document opens. I expect it
is the same for a form, but I have not tried it. Try this:

Tools > Customize > Events

You can set macros for Document loading finished (for example). There is
a drop-down in the bottom for "Save in". Set this to the form, not
LibreOffice since you only want this for your specific form / document.

Next, you want a macro that is triggered when you move to the next
record. I don't remember off hand if you can do this (I have not looked
at it in a few years). If I did, I probably mention it in AndrewBase.odt
if I ever did this specifically. I just don't remember and I do not have
time to look it up right now.


On 02/06/2016 04:52 AM, Marion & Noel Lodge wrote:

> Hi Egbert,
>
> If you are running on a Windows machine, I have found ways to do what you
> were asking and I could make some suggestions if that would help.
>
> Noel
> --
> Noel Lodge
> [hidden email]
>
> On 4 February 2016 at 14:59, Egbert Eissing <[hidden email]> wrote:
>
>> I need to fire up a macro automatically when I open a form, or when I move
>> to the next record.
>> There is obviously no form event that allows me to do that. I have placed
>> a simple macro, containing nothing but a message box into all relevant
>> event slots, to see whether any one of them will fire. But none did. This
>> appears to be strange to me, lacking such an important function.I am now
>> using a button to run my macro, but this is unsatisfactory.
>> Does anyone have an idea how I can accomplish my task?Thanks for any
>> help.Egbert
>>
>> --
>> To unsubscribe e-mail to: [hidden email]
>> Problems?
>> http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
>> Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
>> List archive: http://listarchives.libreoffice.org/global/users/
>> All messages sent to this list will be publicly archived and cannot be
>> deleted
>>

--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
Info:  http://www.pitonyak.org/oo.php


--
To unsubscribe e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted
TonyB TonyB
Reply | Threaded
Open this post in threaded view
|

Re: Base - automatically running a macro on form opening

A long set of macros to open & close forms.

To open a form when the database starts
select "Tools > Customize > Events > Open Document.
Click Assign: Macro and assign the DBOpen macro.

HERE ARE THE MACROS.
As I can't send attachments you will have to copy and paste these into your Macro Library

'****** LOAD LIBRARY ******
'Loads all the tools libraries and opens the connection
Sub DBOpen(Optional poEvent As Object)
dim mydbdoc,CurrentDb,mymsg,metb
On Local Error GoTo Error_Sub
        mydbdoc = ""
        metb = ""
        ' load the access library containing the functions similar to MS Access
        If GlobalScope.BasicLibraries.hasByName("Access2Base") then
         If NOT GlobalScope.BasicLibraries.isLibraryLoaded("Access2Base") Then
                GlobalScope.BasicLibraries.LoadLibrary("Access2Base")
                mymsg = "Access loaded"
         End if
        End if
        REM Use some methods from the Tools library.
  If NOT GlobalScope.BasicLibraries.isLibraryLoaded("Tools") Then
    GlobalScope.BasicLibraries.LoadLibrary("Tools")
    mymsg = mymsg & " Tools loaded"
  End If
  'loaded the Standard library which applies to this database
  If NOT GlobalScope.DialogLibraries.isLibraryLoaded("Standard") Then
  GlobalScope.DialogLibraries.LoadLibrary( "Standard" )
  mymsg = mymsg & " Standard dialog loaded"
  end if
 
  mydbdoc = ThisDatabaseDocument
   ' msgbox "The following was loaded " & mymsg ,6 , "Loaded"
        Call OpenConnection(ThisDatabaseDocument)
        call openThisForm
 Exit_Sub:
                Exit Sub
 Error_Sub:
                TraceError("ERROR", Err, "Opening database at DBopen", Erl)
                GoTo Exit_Sub
End Sub




'********** Use this for opening a data form ***********
'we use this to open the main menu when the document first opens
Sub openThisForm(optional openname as variant,optional closefrmname as variant)
        dim sfrmName,openit
 ' This is the variable for the form that must be opened at the start of program
 'the normal form to open is the "noticefrm", but for data entry on household surey
 'we use the demo_menu form. Data entry is restricted this way.
 if IsMissing(openname) then
         sfrmName =  "noticefrm" ' "planningf/demo_menu" '
 else
        sfrmName = openname
 end if
  'Closefrmname is the form with the calling btn on it or one that was sent from a script
 if IsMissing(closefrmname) then
  closefrmname = "noticefrm"
 end if
         call thesearetheforms(closefrmname,sfrmName)
end sub

'**** Use this to open any form from another form ********
'Open a form that may be in a folder. The folders are defined by / i.e plan/planmenu
Sub openHierachForm(optional openname as variant,optional closefrmname as variant)

        dim sfrmName as string
        dim sfrmtoclosename as string
        dim openit, otestform
        'dim canIopenthis as boolean ' These are used to check tha the user is
        'canIopenthis = false "allowed to open & view this form
 ' openname is the variable for the new form that must be opened
 if IsMissing(openname) then
         sfrmName = "noticefrm"
 else
 'the source is the button that was clicked. The button may have a tag in the Additional Information field
 'This tag defines who is allowed to open the form. If there is no tag then anyone can open the form.
  otestform = openname.source.model
  'check to see if the user has permission to open the openname form
  'canIopenthis =  checkstaffnames(otestform)
        'if canIopenthis = false then
        ' msgbox ("Sorry you are not authorised to view this form",6,"Not authorised")
        ' exit sub
        ' end if
        sfrmName = openname.source.model.name
 end if
 'the form we were on when we clicked the "open form" button
 if IsMissing(closefrmname) then
  sfrmtoclosename = openname.source.model.parent.name
 else
  sfrmtoclosename = closefrmname
 end if
        call thesearetheforms(sfrmtoclosename,sfrmName)
end sub
'Changed 9 Sept 2015. The names of the forms to open and close
SUB thesearetheforms(sfrmtoclosename,sfrmName)
'open the new form before closing the original. Prevents "flash" of desktop.
 if thisDatabaseDocument.FormDocuments.hasByHierarchicalName(sfrmName) then
        thisDatabaseDocument.FormDocuments.getByHierarchicalName(sfrmName).open
  else
        msgbox "Sorry I can't find the form " & sfrmName & chr(10) & "Please check the name!",6,"Form not found"
end if
if sfrmtoclosename <> sfrmName then
        if thisDatabaseDocument.FormDocuments.hasByHierarchicalName(sfrmtoclosename) then
                thisDatabaseDocument.FormDocuments.getByHierarchicalName(sfrmtoclosename).close
        elseif ThisDatabaseDocument.FormDocuments.hasbyname(sfrmtoclosename) then
                ThisDatabaseDocument.FormDocuments.getbyname(sfrmtoclosename).close
        else
                msgbox "sorry I can not close the form " & sfrmtoclosename,0,"Not closed form"
        end if
end if 'open & close forms have same name
end sub


Tony Bray
[hidden email]
MacBook Pro 15 inch Mid 2009
2.8 GHz Intel Core 2 Duo, 4 GB RAM,  
Mac OS X  10.11.2
LibreOffice 4.4.5
Scribus 1.4
Parallels Desktop 11.02
Ubuntu 14.04
LibreOffice 4.4.4







--
To unsubscribe e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted