[Solved] Automatic opening form to screen resolution

Discuss the database features
Post Reply
robce64
Posts: 20
Joined: Wed Feb 22, 2012 8:27 pm

[Solved] Automatic opening form to screen resolution

Post by robce64 »

Hello, I would like to make a macro to make me appear automatically when you open the program, a form of menus designed to screen resolution. The screen resolution is set in the macro should not be fixed but is variable depending on the screen you use. On each computer that uses the form should automatically open to full screen, even if the computers have different monitor resolutions.
Thank you! :super:
Last edited by robce64 on Mon May 07, 2012 6:13 pm, edited 1 time in total.
OOo 3.3 Win7 64bit
robce64
Posts: 20
Joined: Wed Feb 22, 2012 8:27 pm

Re: Automatic opening form to screen resolution

Post by robce64 »

it is impossible? :shock:
OOo 3.3 Win7 64bit
robce64
Posts: 20
Joined: Wed Feb 22, 2012 8:27 pm

Re: Automatic opening form to screen resolution

Post by robce64 »

:crazy:
OOo 3.3 Win7 64bit
robce64
Posts: 20
Joined: Wed Feb 22, 2012 8:27 pm

Re: Automatic opening form to screen resolution

Post by robce64 »

:crazy:
OOo 3.3 Win7 64bit
F3K Total
Volunteer
Posts: 1038
Joined: Fri Dec 16, 2011 8:20 pm

Re: Automatic opening form to screen resolution

Post by F3K Total »

Yes!
But if you like anybody to help you solving you problem, you should show, what you, by yourself, did in between (since Sat Feb 25, 2012 8:15 pm), else than banging your head to a wall, to solve the problem. For example, you could search in this or other boards.
Greats R
  • MMove 1.0.6
  • Extension for easy, exact positioning of shapes, pictures, controls, frames ...
  • my current system
  • Windows 10 AOO, LOLinux Mint AOO, LO
JPL
Volunteer
Posts: 130
Joined: Fri Mar 30, 2012 3:14 pm

Re: Automatic opening form to screen resolution

Post by JPL »

Hello,

to display automatically a form in full-screen when opening a database document (".odb"), maybe below a solution:

- install the Access2Base extension (http://extensions.services.openoffice.o ... ccess2base)
- insert next code in a BASIC module of the Standard Library of your db document:

Code: Select all

Sub DBOpen(Optional poEvent As Object)
REM Next 3 lines are for making Access2Base API available
	If GlobalScope.BasicLibraries.hasByName("Access2Base") then _
		GlobalScope.BasicLibraries.LoadLibrary("Access2Base")
	Call OpenConnection(ThisDatabaseDocument)
REM Now to open a form
	OpenForm "myForm"		'	Set the name of your choice ...
	Maximize()
End Sub
- Assign in the main Base window with menu items Tools + Customize... (Events tab) the above Sub ("DBOpen" in the example but use the name of your choice) to the OpenDocument event. Save in the ".odb" file itself.
- Close and re-open the ".odb" file. This will trigger the OpenDocument event.

A variant could be

Code: Select all

Sub DBOpen(Optional poEvent As Object)
Const acForm = 2
Const acDatabaseWindow = 102
REM Next 3 lines are for making Access2Base API available
	If GlobalScope.BasicLibraries.hasByName("Access2Base") then _
		GlobalScope.BasicLibraries.LoadLibrary("Access2Base")
	Call OpenConnection(ThisDatabaseDocument)
REM Now to open a form
	OpenForm("myForm")		'	Set the name of your choice ...
	Maximize()
	SelectObject(acDatabaseWindow)
	Minimize()
	SelectObject(acForm, "myForm")
End Sub
This will minimize the "database window".

NB: This functionality requires at least OO3.3 !

Hoping this will help.
Kubuntu 22.04 / LibO 7.5
Access2Base (LibO).
BaseDocumenter extension (LibO)
ScriptForge (LibO)
Documentation on https://help.libreoffice.org/latest/en- ... bPAR=BASIC
Fernsguitars
Posts: 2
Joined: Wed Jan 10, 2018 12:01 am

Re: [Solved] Automatic opening form to screen resolution

Post by Fernsguitars »

Hi JPL,

I tested your code within the macro used to start a HSQLDB converted database. The first one to open a form fullsize is working and listed here (your code between REM*****)

The second one that also minimalizes the 'database' window however does not open the form window fullsize. Hope it helps within the topic.

Code: Select all

'Instructions for use:
' (1) manually remove any global Class Path to hsqldb.jar if setup in Tools > Options > *Office > Java/Advanced > Class Path
' (2) macro security must be set to Medium (or Low) in Tools > Options > *Office > Security > Macro Security
' (3) place this file in a dedicated (empty) database folder
' (4) add a copy of the HSQLDB engine (hsqldb.jar) to the database folder.
' (5) when copying this code to another .odb, add this macro to: Tools > Customize... > Events > Open Document

Sub Setup 'Tools > Customize... > Events > Open Document 
 'Globalscope.BasicLibraries.LoadLibrary("MRILib")
 On Error Goto ErrorHandler
  'get the current path to this .odb file
	sPathURL = ThisDatabaseDocument.URL
	sPath = ConvertFromURL(sPathURL)
	sName = ThisDatabaseDocument.Title
	iLen = InStr(sPath, sName)
	sPath = Left(sPath, iLen-1)
	    
  'setup Class Path
  ClassPath:
	sClassPath = sPath & "hsqldb.jar"
	If Not FileExists(sClassPath) Then 
		sLine1 = "Please add a copy of the HSQLDB engine (hsqldb.jar) to the current folder :  "
		sLine2 = "NOTE:  This is necessary for proper wizard function, but additional benefits include : " 
		sLine3 = "* enhanced portability of the database-folder"
		sLine4 = "* ensures database compatibility across computers and *Office installations"
		sLine5 = "* guards against inadvertent upgrade of your database since the results are uncertain and irreversible"
		sLine6 = "* hsqldb 2.x provides a built-in database management GUI accessible by clicking hsqldb.jar."
		iButton = MsgBox (chr(13) & sLine1 & chr(13) & chr(13) & sPath & chr(13) & chr(13) & sLine2 & chr(13) & sLine3 & _
		chr(13) & sLine4 & chr(13) & sLine5 & chr(13) & sLine6, 18, "hsqldb.jar not found")
		If iButton = 3 Then Exit Sub 'ThisDatabaseDocument.close(True)
		If iButton = 4 Then Goto ClassPath
	End If
	sClassPath = ConvertToURL(sClassPath)
	ThisDatabaseDocument.DataSource.Settings.JavaDriverClassPath = sClassPath
    
  'get the HSQL database name from the current folder
	NextFile = Dir(sPath, 0)
	While NextFile <> ""
		If (Right(NextFile, 7) = ".script") Then dbName = (Left(NextFile, Len(NextFile)-7))
		NextFile = Dir
	Wend
    
	If dbName = Empty Then 
		sLine1 = "Optionally provide a name for your back-end data files. "
		sLine2 = "NOTE: The particular name is not important. The default below will suffice. "
		dbName = InputBox(sLine1 & chr(13) & chr(13) & sLine2, "Create a new database    *   JDBC  |  HSQL database engine  |  non-embedded data files   *", "mydb")
		If dbName = "" Then dbName = "mydb"
	End If
    
  'check for existing database
	sLine1 = "A new database will be created in the current folder:  "
	sLine2 = "NOTE: This folder constitutes your ""database."" "
	sLine3 = "A dedicated database folder is fully portable, and as such it may be renamed or moved as desired."
	sLine4 = "NOTE: This Base front-end file (" & sName & ") must remain in this database folder.  "
	sLine5 = "You may rename this file as desired, but do maintain the .odb extension if visible. Create a desktop shortcut to this file as desired."
	sLine6 = "NOTE: The back-end HSQL data files will be named: " & dbName & ".*  "
	sLine7 = "These files must also remain in this database folder."
	If Not FileExists(sPath & dbName & ".script") Then MsgBox sLine1 & chr(13)_
		& sPath & chr(13) & chr(13) & sLine2 & sLine3 _
		& chr(13) & chr(13) & sLine4 & sLine5 _
		& chr(13) & chr(13) & sLine6 & sLine7 _
		, 64, "Please Read"
     
  'setup Data Source URL
	sURL_prefix = "jdbc:hsqldb:"
	sURL_args = ";default_schema=true;shutdown=true;hsqldb.default_table_type=cached;get_column_name=false"
	sURL = sURL_prefix & "file:///" & sPath & dbName & sURL_args
	ThisDatabaseDocument.DataSource.URL = sURL
	
REM*************************************************************************
REM Next 3 lines are for making Access2Base API available
   If GlobalScope.BasicLibraries.hasByName("Access2Base") then _
      GlobalScope.BasicLibraries.LoadLibrary("Access2Base")
   Call OpenConnection(ThisDatabaseDocument)
REM Now to open a form
   OpenForm "my form"      '   Set the name of your choice ...
   Maximize()
REM*************************************************************************
	Exit Sub

  ErrorHandler: 
	MsgBox "Error " & Err & ": " & Error$ & " (line : " & Erl & ")", 16, "Setup: macro code error"
End Sub
openoffice 4.1.2 / Windows 10 pro
JPL
Volunteer
Posts: 130
Joined: Fri Mar 30, 2012 3:14 pm

Re: [Solved] Automatic opening form to screen resolution

Post by JPL »

@ Fernsguitars

Thanks for the info.
(I don't remember what I tested effectively >5 years ago ... )

Anyway this works for me:

Code: Select all

	SelectObject(acDatabaseWindow)
	Minimize()
	OpenForm("myForm")      '   Set the name of your choice
	Maximize()
Regards.
JPL
Kubuntu 22.04 / LibO 7.5
Access2Base (LibO).
BaseDocumenter extension (LibO)
ScriptForge (LibO)
Documentation on https://help.libreoffice.org/latest/en- ... bPAR=BASIC
Fernsguitars
Posts: 2
Joined: Wed Jan 10, 2018 12:01 am

Re: [Solved] Automatic opening form to screen resolution

Post by Fernsguitars »

@ JPL

Thanks! Last year and this year I work on my business database, and sometimes I try to get info at the forum, so I will try sometimes to contribute as wel - only taking info is a bit silly - but that is a bit off topic!
openoffice 4.1.2 / Windows 10 pro
Post Reply