OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Form To Form Code Error

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base
View previous topic :: View next topic  
Author Message
MRadysh
General User
General User


Joined: 13 Feb 2009
Posts: 19
Location: Woodbury, MN

PostPosted: Wed Feb 18, 2009 12:51 pm    Post subject: Form To Form Code Error Reply with quote

This is a code that I want to use on a command button to open a form.
It does not work and an error appears on:
OpenForm = formContainer.loadComponentFromURL("test","_blank",0,aProp())

Does anyone know how to fix this?

Thanks in advance.

REM----------------------------------------------------------------------------------------------------------
function OpenForm( formContainer as variant, oConnection as variant, sFormName as string) as variant
Dim aProp(2) As New com.sun.star.beans.PropertyValue
aProp(0).Name = "ActiveConnection"
aProp(0).Value = 1
aProp(1).Name = "OpenMode"
aProp(1).Value = "open"
REM OpenForm = formContainer.loadComponentFromURL("test","_blank",0,aProp())
OpenForm = formContainer.loadComponentFromURL("test","_blank",0,aProp())[/color]
end function

function getFormsTC() as variant
getFormsTC = thisComponent.Parent.getFormDocuments
end function

function getConnectionTC() as variant
getConnectionTC = thisComponent.Drawpage.Forms(0).ActiveConnection
end function

sub OpenForm_Assets_Input( oev as variant )
sFormName = "SFAbrasion"
OpenForm( getFormsTC, getConnectionTC, sFormName )
end sub
Back to top
View user's profile Send private message
RPG
Super User
Super User


Joined: 24 Apr 2008
Posts: 2697
Location: Apeldoorn, Netherland

PostPosted: Wed Feb 18, 2009 1:49 pm    Post subject: Howto openform since switchboard exist Reply with quote

Hello

I have post in the other forum a shorter example what only work with OOo3.1 and higher

Edit by Romke
Quote:
This is Only for what is the best post to start
Update 6 November 2009

When You have
OOo 3.1 or higher goto the the post with this date:PostPosted: Mon Jun 08, 2009 7:05 am.
When you have OOo3.00 or 2.4 then maybe a post eatlier.
When you have OOo2.4 or earlier then follow the link

In an other post I have explaind some other things about how to open forms and what problem you can expect.


You want open a form, with openform.
I don't know if you have special reason to do it with a macro but first I will attend you on switchboard.

http://www.baseprogramming.com/resources.html
The link points you to the download page. I can tell nothing about switchboard but I do trust the maker.

If you really like macros then I think it is important to know for you that there is a new instruction:loadComponent

http://www.oooforum.org/forum/viewtopic.phtml?t=79150
http://www.oooforum.org/forum/viewtopic.phtml?t=79384
http://www.oooforum.org/forum/viewtopic.phtml?t=77885&highlight=thisdatabasedocument


This three links explain how it is working.
I must make clear that not all versions of OOo acts act the same and loadcomponent can maybe only used above version 2.4 and then there can be problems. There are bleeding edges

If you want use macros tell first what version you use

This is added to post later
When you use OOo2.40 and lower I think code in following will not work for you.
When you use OOo3.01 and lower then read post with date : Sun Mar 01, 2009 6:25 am
when you use OOo3.1 and higher then read later posts.

Romke


Last edited by RPG on Thu Apr 21, 2011 11:29 am; edited 4 times in total
Back to top
View user's profile Send private message
RPG
Super User
Super User


Joined: 24 Apr 2008
Posts: 2697
Location: Apeldoorn, Netherland

PostPosted: Sun Mar 01, 2009 6:25 am    Post subject: Howto openform open a form in OOo-Base Reply with quote

Hello

I do not know if you still need this macro. Your question makes me clear that it is to difficult for people using the macro who exist. It was for also not easy for me. But now I succeed in making it a little less difficult.
The rest of the text is for all people

I do add again a openform macro on this forum.
Very much people want open a form with a macro and there are several macro's on this forum. I did post earlier an example. The first one was copied from other person. Later I did make an easier one with checking on errors and now this is again easier. It means I do under stand more the API.

For people who are starting with OOo base and with programming If you want open a form try first Switchboard of Benitez
http://www.baseprogramming.com/resources.html

For better understanding forms, do study his manual about forms
http://www.geocities.com/rbenitez22

If this is the first time you use macro's do study
this link
http://api.openoffice.org/basic/man/tutorial/tutorial.pdf
And the help file of you OOo basic give a lot information.

I will not explain all questions read the manuals.
I knew it very difficult to find good information so I also add some important links

You can search with macros I did post some macro's but Villeror and Voobase did post some nice examples for how to search without macro's
http://user.services.openoffice.org/en/forum/viewtopic.php?f=39&t=10036
http://www.oooforum.org/forum/viewtopic.phtml?t=80648
The last link is an example database

This macros is build on other macros read if you want this
http://www.oooforum.org/forum/posting.phtml

I hope this help you
I have edit this post so you can better read it

Romke





For inserting macros I add also text.
Quote:

What is the good place?
a)Close as much as possible of OOo. That make it less confusing.
But you should not close your program / form and not close the database
b)remember the name of your program / form or Database
c)Choose now the name of your program / form or Database
d) If this is the first time you are working with macros there are no macros in existing macros click on new.
e) A new popup ask for a name accept the module1
f) Now you get a nearly blank window past your macro here.





Code:

REM  *****  BASIC  ****
option explicit

sub Call_function_and_or_Sub
dim form
form=thiscomponent.drawpage.forms.getbyname("beginpersonen")

dim oNewform
'oNewform=openform_big("boeken","input04")
oNewform=openform_small_30("testcheckbox",thisdatabasedocument)
'oNewform=openform_small_30("testcheckbox",thiscomponent)
'oNewform=openform_big_30("input04","boeken")
'oNewform=openform_small("lijst_box","boeken")

' This give an example how you use the retun value
gotorecord(oNewform,"NameOfForm",3)
end sub



'++++++++++++++++++++++++++++++++++++++

function openform_small_30(sWriterForm as string ,oDocument as object) as object
' This functtion does use possiblilities of a high OOo version
' I think that the loadcomponent can be used from OOo 2.40 but I cannot test it
' The small I use has meaning for another limitation.
' It can only open a form in the current database
' It is a function, functions do return a value.
' The value returned is the object of the form and this can be used
dim oController,goforname
dim oDatabaseSource ,oWriterForm

select   case  oDocument.implementationname
      case "SwXTextDocument"
            ' Komt hier als het thiscomponent is
            oController=oDocument.parent.CurrentController
      case   "com.sun.star.comp.dba.ODatabaseDocument"
            ' Als er thisdatabasedocument wordt meegegeven
            oController=oDocument.CurrentController

      case else : print oDocument.implementationname & "   helllo"
         end

end select



'This control if your version has the capabillities for this macro
if not HasUnoInterfaces(oController,"com.sun.star.sdb.application.XDatabaseDocumentUI") then
   msgbox "Your version of Open Office does not have this capabillities" & chr(13) _
   & "The program will stop"
   end
end if
if  oController.datasource.DatabaseDocument.FormDocuments.hasbyname( sWriterForm) then
      ' The array give some information to the file who is be opend
      openform_small_30=oController.loadcomponent( com.sun.star.sdb.application.DatabaseObject.FORM,sWriterForm,false)
      exit function ' Leave function
      ' All line next in this function are for error handling
   else
      msgbox  "I cannot find this name " & sWriterForm & CHR(13)_
      & "The formnames are case sensitive" & CHR(13)_
          & "in this file"
end if
end ' stop the program
end function



function openform_big(SDatabaseSource as string,sWriterForm as string )
'I believe this must work on all OOo version
' Give the name of the database source. It must be an registerd database
'Input
'   the name of the database or datasource name
'    The name of the form name I mean writer document
'Output
'   The object of the writer document


dim oDatabaseSource ,oWriterForm
Dim oDatabaseContext As Object

oDatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")

if  oDatabaseContext.hasbyname(SDatabaseSource) then
   'There is a database from that name
      oDatabaseSource=oDatabaseContext.getbyname(SDatabaseSource)
      if oDatabaseSource.DatabaseDocument.FormDocuments.hasbyname( sWriterForm) then
         ' The array give some information to the file who is be opend
         Dim aProp(1) As New com.sun.star.beans.PropertyValue
         aProp(0).Name = "ActiveConnection"
         aProp(0).Value = oDatabaseSource.getConnection("", "")
         aProp(1).Name = "OpenMode"
         aProp(1).Value = "open"
         ' looks for a object
         openform_big= oDatabaseSource.DatabaseDocument.FormDocuments.loadComponentFromURL( sWriterForm,"_blank",0,aProp())
         exit function
         ' All line next in this function are for error handling
      else
         msgbox  "I cannot find this name " & sWriterForm & CHR(13)_
         & "The formnames are case sensitive" & CHR(13)_
             & "in this file"
          end if
   else
   msgbox  "I cannot find this name " & SDatabaseSource & CHR(13)_
    & "The formnames are case sensitive" & CHR(13)
   ' & "in : " & getFormsTC.name
    ' The document you want have does not exist we stop complete
end if
end ' stop the program
end function


'+++++++++++++++++++++++++++++++++++++++
      
      
sub gotorecord(oWriterdoc,sFormname,record as long)

' let goto record in new file
if oWriterdoc.drawpage.forms.hasbyname(sFormname) then
   with oWriterdoc.drawpage.forms.getbyname(sFormname)
      if  .isloaded = false then    .load
      .absolute(record)
   end with
else
   print "The form name does not exist"
end if

end sub
Back to top
View user's profile Send private message
RPG
Super User
Super User


Joined: 24 Apr 2008
Posts: 2697
Location: Apeldoorn, Netherland

PostPosted: Mon Jun 08, 2009 1:05 am    Post subject: Reply with quote

Hello

In OOo there are new capabilities one of them is how to open a form.
Opening and closing a form is much easier then before. You have to use the new predifine ThisDatabaseDocument object.

When you use this then you can open a form and closing a form. It is only capable to open a form in the current database. You can use it maybe also to open a form in an other database but I did not code it

The code I did wrote is a little long. The reason I did add some testing so you can knew where your problem exist. I hope this help you.

Romke




Code:
sub openform
' In this sub are several extra tests. The reason for this tests are:
' How more OOo devolps how more different there is between version.
' This code use thing from version 3.1 and higher
'http://api.openoffice.org/docs/common/ref/com/sun/star/sdb/XSubDocument.html
' With this code you cannot open a form in an other database.
dim oNewForm ' This object is for subdocument.
dim oNewFormopen ' This is the text document. Now you can reach the forms and the controls
dim sNewFormName
sNewFormName="plaatjeobject02" ' add here you own form name
' Test if your version of OOo is capabel for this code
if  GetSolarVersion < 310 then
   print "Your version of OpenOffice to old for this code"
   end
end if
' Go for the object of the subdocument
if  ThisDatabaseDocument.FormDocuments.hasbyname(sNewFormName) then
      oNewForm=ThisDatabaseDocument.FormDocuments.getbyname(sNewFormName)
   else
       Print "This database does not have a form with this name"
end if

if not HasUnoInterfaces(oNewForm,"com.sun.star.sdb.XSubDocument") then
   ' It is possible that you use a mapname and this is not good working
   ' for that reason I did not work it out.
   msgbox "Your version of Open Office does not have this capabillities" & chr(13) _
   & "The program will stop"
   end
end if
'print oNewForm.implementationname
'end

' All things are tested and good open the form
oNewFormopen=oNewForm.open ' This give also back an object with is the same as thiscomponent
gotorecord(oNewFormopen,"MainForm",2)
end sub


sub gotorecord(oWriterdoc,sFormname,record as long)

' let goto record in new file
if oWriterdoc.drawpage.forms.hasbyname(sFormname) then
   with oWriterdoc.drawpage.forms.getbyname(sFormname)
      if  .isloaded = false then    .load
      .absolute(record)
   end with
else
   print "The form name does not exist"
end if

end sub


Last edited by RPG on Mon May 10, 2010 12:10 pm; edited 1 time in total
Back to top
View user's profile Send private message
RPG
Super User
Super User


Joined: 24 Apr 2008
Posts: 2697
Location: Apeldoorn, Netherland

PostPosted: Wed Jan 27, 2010 3:13 am    Post subject: Reply with quote

Tutorial about open a form with macros.

There are coming frequent questions about opening a form. Since OOo has embedded all in one document there are more ways to do it. Basicly there is no change for opening a form since OOo started.
you have to do:
a) Making a connection to the database
b) Open that form with the connection to the database.

When you design a database it is real important to design your tables careful. This makes no difference for OOo it is all the same. But when you use OOo it is also important to design careful how you want use the forms. You can have all the forms inside your database document or outside your database document even you can mixed it. It to the designer to make a choice. When you want open a form which is embedded in the database document with macros who are not embedded in the database and without running the database self then you have to take care that your data changes are written to the database. This method is not recommend.

Summary
When you want open a form there is now a difference between several thing
a) Open a stand alone form
Use the old method as in begin of this thread

b) Open an embedded form from outside the database.
This method is better not to use. There not all data automatic is stored in the database. You have to close the connection at the end.
When you need this methode I think it is better to bring your forms outside the database document

c) Open an embedded form from inside side the database document.
I think this is the best methode for most people and easy without complication

Romke
Back to top
View user's profile Send private message
eleleleelelelelelelele
General User
General User


Joined: 29 Apr 2010
Posts: 9

PostPosted: Mon May 10, 2010 11:42 am    Post subject: Reply with quote

I used this code and it works great,

only 1 fix -
print oNewForm.implementationname
end
delete the end - it finishes the sub without continuing.

pitty I searched for 2 hours, and tryied so many other sample codes that didn't work, and tried to debug them before I reached this one - you should find a way to erase the wrong sample codes. maybe create a official site for sample codes - and there locate only the good ones.
Back to top
View user's profile Send private message
RPG
Super User
Super User


Joined: 24 Apr 2008
Posts: 2697
Location: Apeldoorn, Netherland

PostPosted: Mon May 10, 2010 12:13 pm    Post subject: Reply with quote

Hello

Thank you for that point. I did not have seen it and you are the first who told it. I don't know why I did have removed it.

I have out comment the two lines

Romke
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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