| View previous topic :: View next topic |
| Author |
Message |
Helmut_Seidel General User

Joined: 30 Oct 2005 Posts: 13
|
Posted: Sat Feb 04, 2006 1:56 pm Post subject: display database-form on star-up |
|
|
hello everybody,
can anybody tell me wether its possible to open a certain database form anytime a database (.odb-file) is opened (on startup) and how this is done.
thanks a lot
helmut |
|
| Back to top |
|
 |
DrewJensen Super User


Joined: 06 Jul 2005 Posts: 2616 Location: Cumberland, MD
|
Posted: Sat Feb 04, 2006 3:11 pm Post subject: |
|
|
The short answer is NO. There is no built in support for this feature.
I have been trying to work on a work around, but with less then stellar results to date.
Here is what I have been able to come up with.
The OpenOffice.org API does has an event for 'Open Document'. In a basic macro handler for this event you can find a particular database just as it is about to be opened.
Here is a macro that will dot this:
| Code: |
const cBaseTitle = " - OpenOffice.org Base"
global isInOnOpenAgain as integer
sub onOpenDocumentMain
dim df as variant
dim DBName as string
'atj 02/02/06
'dim HideDBFrame as boolean
dim HideDBFrame as variant
dim i as integer
dim oDispatchHelper
'static isInOnOpenAgain as boolean
df = Stardesktop.Frames
If RIGHT((df(df.count-1).title), len(cBaseTitle)) = cBaseTitle Then
if isInOnOpenAgain > 0 then
HideDBFrame = df(df.count-1)
dbName = left((df(df.count-1).title), len(df(df.count-1).title) - len(cBaseTitle))
if OpenDefaultForm( dbName ) then
'wait 1000
'oDispatchHelper = createUnoService( "com.sun.star.frame.DispatchHelper" )
'oDispatchHelper.executeDispatch( HideDBFrame, ".uno:Min", "", 0, Array() )
HideDBFrame.getComponentWindow.setVisible( False )
'HideDBFrame.getContainerWindow.setVisible( False )
'xRay.xRay HideDBFrame
endif
isInOnOpenAgain = 0
else
isInOnOpenAgain = 1
endif
End if
end sub
sub OpenDefaultForm( dbName as string ) as boolean
' version 1
' this is the slow version...
' first thing lets see if we have an entry in dbMaster for this
' rgistered dbname
dim defForm as string
dim i as integer
defForm = checkForDBEntry(dbName)
if defForm <> "" then
isInOnOpenAgain = 0
OpenForm( getFormContainer( dbName ), getConnection( dbName ), defForm )
OpenDefaultForm = true
else
OpenDefaultForm = False
end if
end sub
|
This macro makes use of another function checkForDBEntry(dbName)
| Code: |
function checkForDBEntry( dbName as string ) as string
dim conn as variant
dim stmt as variant
dim defForm as string
dim rs as variant
conn = getContext.getByname("dbMaster").getConnection("SA","")
stmt = conn.createStatement
rs = stmt.executeQuery( "SELECT * from ""DB_UNIVERSE"" WHERE ""DB_NAME"" = '" & dbName & "'" )
if rs.isBeforeFirst then
rs.next
defForm = rs.columns.getByname( "DB_NAGIVATOR_FRM").getString
checkForDBEntry = defForm
else
checkForDBEntry = ""
endif
end function
|
And this function in turn uses a couple of helper functions and a database I created named dbMaster. The dbMaster database has two tables, DB_UNIVERSE and FORMS_SETTINGS setup as follows:
DB_UNIVERSE
FORMS_SETTINGS
The helper functions are
| Code: |
global DBContext as variant
global DBFormsContainer as variant
global DbConnection as variant
function OpenForm( formContainer as variant, oConnection as variant, sFormName as string) as variant
Dim aProp(1) As New com.sun.star.beans.PropertyValue
aProp(0).Name = "ActiveConnection"
aProp(0).Value = oConnection
aProp(1).Name = "OpenMode"
aProp(1).Value = "open"
OpenForm = formContainer.loadComponentFromURL(sFormName,"_blank",0,aProp())
wait 1000
end function
function getFormContainer( aDBName as string ) as variant
dim DBFrame
dim DBSource
if isEmpty( DBFormsContainer ) then
DbSource = getContext.getByname(aDbName)
DBFrame = StarDeskTop.loadcomponentfromURL(DBSource.DataBaseDocument.URL,"_Hidden", 63, Array())
DBFormsContainer = DBFrame.getFormDocuments
DbConnection = DBFrame.DataSource.getConnection("","")
DBFrame.CurrentController.Frame.Close( False )
end if
getFormContainer = DBFormsContainer
end function
function getConnection( aDBName as String) as variant
dim DBFrame
dim DBSource
if isEmpty( DbConnection ) then
DbConnection = getContext.getByname(aDbName).getConnection("SA","")
end if
getConnection = DbConnection
end function
|
the helper functions need to be rewritten as they are recycled from a different project and aren't really right for this use, but work for the moment.
Here is the big problem I am having. because we are in the Open Document event on the database opening we can not tell the frame to close, nor it seems to become hidden. So far the only thing I have been able to do is close the component window. This leaves the frame on the screen, but without any of the forms, tables, or queries listed. At first this looks like a dead end, but what I am hoping to do now is to turn this to an advantage. Because, I can already drop and add menus to this frame. So one could setup custom menus for the database application. The thing now is to figure out how to place our own form into the component window area, versus the standard listings of tables, queries, forms and reports.
If you can run any further with this code let me know. As I get further along I will post what I have up to the forum.
Drew _________________ Blog - http://baseanswers.spaces.live.com/ |
|
| Back to top |
|
 |
kodiak11125 Newbie

Joined: 21 Sep 2006 Posts: 2 Location: Rockford, IL
|
Posted: Thu Sep 21, 2006 10:09 am Post subject: default form at startup |
|
|
| This feature is a MUST where users are not database experts. I work in a factory environment. Uses are not computer saavy. They must be able to click an icon and go directly to a form. |
|
| Back to top |
|
 |
DrewJensen Super User


Joined: 06 Jul 2005 Posts: 2616 Location: Cumberland, MD
|
Posted: Thu Sep 21, 2006 10:13 am Post subject: |
|
|
True enough.
But I assume the person building the database will have enough 'savy' to render a failry simple macro.
The solution today is quite simple. Create a stand alone form to act as the navigator. If an actual example of this would help then I would be glad to supply one. The macro used to open the other forms or reports can be quite generic, I think. |
|
| Back to top |
|
 |
mercurion General User

Joined: 19 Jun 2007 Posts: 6
|
Posted: Mon Jul 02, 2007 1:57 am Post subject: |
|
|
I agree with drew regarding the workarounds. However I do have a similar kind of problem with the end user being not so computer savvy.
I am developing a database with a similar workaround where an .odt file would work as a switchboard for the user to go to different parts of the database. However having said this, the user still has to register the database on their own. This includes going through the OOoBase menu options and directing the database stored location into OOoBase.
Thus my problem is rather simple yet complicated at the same time. How would one work around this ? I have not found a solution for this yet as most queries were with regards to local systems and where export involves the developer installing the system in situ. Anybody with solutions to this yet?  |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|