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

Open a new form from form with button insert record

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


Joined: 18 Mar 2009
Posts: 2

PostPosted: Wed Mar 18, 2009 2:28 am    Post subject: Open a new form from form with button insert record Reply with quote

Hi all,

I'm trying to write a macro to open a form from a main form with a push button. In the new form I'm supposed to add a record linked to the calling form.

Here comes the code (still to be completed though).

Code:

GLOBAL myindex as integer

sub ApriForm2(oEvent)
   Dim lNameCol
   Dim oForm
   Dim oForms
 
   ' Get the present form
   oForm = oEvent.Source.getModel().getParent()   
 
   lNameCol = oForm.findColumn("ID") 'get the ID column index
   myindex=oForm.getInt(lNameCol) ' get the value (integer)
   
   'Open the new form (e.g. Form2).
   OpenForm(getFormsTC, getConnectionTC,sFormName)
   
   oForms = thiscomponent.drawpage.forms
   'Xray oForms
   
   
   oForm = oForms.getbyIndex(0)
   Xray oForm ' Debugging
   
   ' Get the index of column "test"
   lNameCol = oForm.findColumn("test")
   Xray lNameCol ' Debugging
   oForm.updateShort(lNameCol, myindex) ' Insert value myindex into column "test"
   
End Sub


The weird thing is that lNameCol should be = 4, and it actually gets the right value if I debug with Xray (Xray oForm). If I comment that line, lNameCol gets the value 0, which is clearly wrong! How can it be?

Any clue?

Thanks,
Stef
Back to top
View user's profile Send private message
Senbee
Newbie
Newbie


Joined: 18 Mar 2009
Posts: 2

PostPosted: Wed Mar 18, 2009 2:37 am    Post subject: Reply with quote

I solved the problem adding

Code:

oForm = oForms.getbyIndex(0)
oForms.load() ' <- added this


Question...why do I need that?

Stef
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 Mar 18, 2009 2:45 am    Post subject: Reply with quote

Hello

Study the tutorials of Benitez

http://www.geocities.com/rbenitez22/OOo/index.html

You get the good answer what you ask is the column index but that is not the record number. There are a lot of examples on this forum.

Global
I think you must not use Global for creating variables but dim or private look in the help file for the difference. You OOo version have a help file.

Also it is important to use
OPTION EXPLICIT
Use this as the first line in your basic code in every module. Maybe you get more error codes, but you less program errors.

Romke
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Wed Mar 18, 2009 2:58 am    Post subject: Reply with quote

A short alternative (5 lines) to open any form through any event triggered by any control on a main form(not attached to a subform):
[Solved] Macros for listbox contents and new form buttons
_________________
Rest in peace, oooforum.org
Get help on https://forum.openoffice.org
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