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
tonybsa@mac.me
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: users+unsubscribe@global.libreoffice.org
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
Context
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.