| View previous topic :: View next topic |
| Author |
Message |
Senbee Newbie

Joined: 18 Mar 2009 Posts: 2
|
Posted: Wed Mar 18, 2009 2:28 am Post subject: Open a new form from form with button insert record |
|
|
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 |
|
 |
Senbee Newbie

Joined: 18 Mar 2009 Posts: 2
|
Posted: Wed Mar 18, 2009 2:37 am Post subject: |
|
|
I solved the problem adding
| Code: |
oForm = oForms.getbyIndex(0)
oForms.load() ' <- added this
|
Question...why do I need that?
Stef |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Wed Mar 18, 2009 2:45 am Post subject: |
|
|
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 |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 10065 Location: Germany
|
|
| Back to top |
|
 |
|