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

SOLVED opening form and at specific record from subform
Goto page 1, 2  Next
 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base
View previous topic :: View next topic  
Author Message
KCPhoto
General User
General User


Joined: 04 Sep 2010
Posts: 19
Location: RIchmond, KY

PostPosted: Sun Sep 05, 2010 5:35 am    Post subject: SOLVED opening form and at specific record from subform Reply with quote

I posted part of this in the thread where I found this code, but want to clarify what I need. Sorry for the duplication.

I need help determining why I can't find a column in a subform record in this macro.
I am calling the macro from within the subform with a mouse click.

Code:
REM  *****  BASIC  *****

Sub OpenShoot

odoc = thiscomponent
oform = odoc.drawpage.forms.getbyindex(0)  'What does this return???

MyID = oForm.GetString(oForm.FindColumn("ShootID"))
 'ShootID is column in a subform table on this form


'Open the form Shoot
ThisDatabaseDocument.FormDocuments.getByName("Shoot").open()

odoc2 = thiscomponent
oform2 = odoc2.drawpage.forms.getbyindex(0)

'Filter the form Shoot to show the record from the previous subform
oform2.filter =("ShootID = " & myindex)
oform2.ApplyFilter = True
   
'Reload the form to show data
Oform2.reload

End Sub


The column I am searching for is in a subform. Is this my problem? When the macro runs I get an error saying "The column name 'ShootID' is unknown"

The form is called "Clients" and the field I need, "ShootID" is in the subform "ShootSubform".

I give this information because I need very specific help. I am brand new to base.

I suspect that * odoc = thiscomponent * is returning the parent form. I can't find the arguments for this command to direct it to the subform so that I can find the column in that subform.

I am using version 3.2.1 of OpenOffice and have been successful opening the form with the statement:
ThisDatabaseDocument.FormDocuments.getByName("Shoot").open()

Thanks,
Kenny


Last edited by KCPhoto on Mon Sep 06, 2010 5:20 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
RPG
Super User
Super User


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

PostPosted: Sun Sep 05, 2010 9:06 am    Post subject: Reply with quote

Hello

Use the base tools.

Her is an explanation
http://user.services.openoffice.org/en/forum/viewtopic.php?f=20&t=31801&p=145187#p145187

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


Joined: 04 Sep 2010
Posts: 19
Location: RIchmond, KY

PostPosted: Sun Sep 05, 2010 3:34 pm    Post subject: Reply with quote

Thank you for the reply.
Kenny


Last edited by KCPhoto on Mon Sep 06, 2010 5:26 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
KCPhoto
General User
General User


Joined: 04 Sep 2010
Posts: 19
Location: RIchmond, KY

PostPosted: Mon Sep 06, 2010 5:25 am    Post subject: Making Progress - need help with Filter line Reply with quote

I have been able to retrieve the field I need to filter the called form. However, I now have a problem with my filter line of code.

Code:
Sub OpenShoot

dim oDoc,oDrawpage,oForms,oMainForm,oSubForm,oMyID,otblctrl
oDoc=ThisComponent
oDrawpage=oDoc.drawpage
oForms=oDrawpage.forms
oMainForm=oForms.getbyname("MainForm")
oSubForm=oMainForm.getByName("ShootSubform")
otblctrl=oSubForm.getByName("SubForm_Grid")
oMyID=otblctrl.getByName("ShootID")


'Open the form Shoot
ThisDatabaseDocument.FormDocuments.getByName("Shoot").open()

'Create 2 more variables
odoc2 = thiscomponent
oform2 = odoc2.drawpage.forms.getbyindex(0)

'Filter the form Shoot to show the record from the previous subform
oform2.filter =("ShootID = " & oMyID)
oform2.ApplyFilter = True
   
'Reload the form to show data
Oform2.reload


End Sub


In this line
oform2.filter =("ShootID = " & oMyID)

I get the error message:
"Incorrect Property Value"

The ShootID field is an Integer value (Key field for the Shoot table). I'm trying to set oMyID to the Record Key of the selected record in the subform to show it on the new form that I open.

Can anyone tell me what I have done wrong? Do I need to define oMyID as an Integer variable or is my syntax wrong?

Thanks,
Kenny
Back to top
View user's profile Send private message Visit poster's website
KCPhoto
General User
General User


Joined: 04 Sep 2010
Posts: 19
Location: RIchmond, KY

PostPosted: Mon Sep 06, 2010 7:43 am    Post subject: Still struggling Reply with quote

By declaring my variable oMyID alternatively as an Integer and then a String variable, I have determined that the line
oMyID=otblctrl.getByName("ShootID")
is returning an an Object and cannot be a string or an integer.

How do I incorporate this into a filter command?

oform2.filter =("ShootID = " & oMyID) does not work, I assume, because oMyID is not a string value as required by the filter.

How do I get the value from the oMyID Object and convert it to a string in the filter?

I know I am rambling here, but I am hoping someone will see I am making some progress and step in to help.

Thanks,
Kenny
Back to top
View user's profile Send private message Visit poster's website
KCPhoto
General User
General User


Joined: 04 Sep 2010
Posts: 19
Location: RIchmond, KY

PostPosted: Mon Sep 06, 2010 8:33 am    Post subject: Reply with quote

Well, I got the filter to work using CurrentValue on the object variable. Now...

The filter is running on the original form "Clients" instead of the form I have just opened. How do I set the focus to the new form before executing the filter and reload?

Code:

Sub OpenShoot

dim oDoc,oDrawpage,oForms,oMainForm,oSubForm,otblctrl,oMyIDvalue
dim oMyID as object

oDoc=ThisComponent
oDrawpage=oDoc.drawpage
oForms=oDrawpage.forms
oMainForm=oForms.getbyname("MainForm")
oSubForm=oMainForm.getByName("ShootSubform")
otblctrl=oSubForm.getByName("SubForm_Grid")
oMyID=otblctrl.getByName("ShootID")
oMyIDvalue = oMyID.CurrentValue


'Open the form Shoot
ThisDatabaseDocument.FormDocuments.getByName("Shoot").open()


odoc2 = thiscomponent
oform2 = odoc2.drawpage.forms.getbyindex(0)

'Filter the form Shoot to show the record from the previous subform
oform2.filter =("ShootID = " & oMyIDvalue)

oform2.ApplyFilter = True
   
'Reload the form to show data
Oform2.reload

End Sub


Thanks,
Kenny
Back to top
View user's profile Send private message Visit poster's website
RPG
Super User
Super User


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

PostPosted: Mon Sep 06, 2010 10:45 am    Post subject: Reply with quote

Hello

First it is real nice you succeed in making a working macro. I knew it is real difficult to set the first steps. Be happy with your code and do not forget to study also the Basetools. You can find all information in the thread I did point to. In the code in that link there is also a link where you can find the basetools.

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


Joined: 04 Sep 2010
Posts: 19
Location: RIchmond, KY

PostPosted: Mon Sep 06, 2010 10:54 am    Post subject: Reply with quote

I have searched and used trial and error on this all day. I wislh there was more documentation available somewhere.

I wish to make the latter part of this macro execute on the newly opened form "Shoot". Can anyone please tell me what to put after this line

oDoc2 = oDataBase.FormDocuments.GetByName("Shoot")

to let the filter run on the form I have just opened.


Code:

Sub OpenShoot

dim oDoc,oDrawpage,oForms,oMainForm,oSubForm,otblctrl,oMyIDvalue
dim oMyID as object

oDoc=ThisComponent
oDrawpage=oDoc.drawpage
oForms=oDrawpage.forms
oMainForm=oForms.getByName("MainForm")
oSubForm=oMainForm.getByName("ShootSubform")
otblctrl=oSubForm.getByName("SubForm_Grid")
oMyID=otblctrl.getByName("ShootID")
oMyIDvalue = oMyID.CurrentValue


'Open the form Shoot
ThisDatabaseDocument.FormDocuments.getByName("Shoot").open()


oDatabase = ThisComponent.Parent   
oDoc2 = oDataBase.FormDocuments.GetByName("Shoot")  '***CANT GET FROM HERE TO drawpage!!
'WHAT DO I NEED HERE?
oDocView = oDoc2.getCurrentController()  '***ERROR getCurrentController not available
oDrawpage2 = oDocView.drawpage
oForms2 = oDrawpage2.forms
oForm2 = odoc2.drawpage.forms.getbyName("ShootForm")

'Filter the form Shoot to show the record from the previous subform
oForm2.filter =("ShootID = " & oMyIDvalue)
oForm2.ApplyFilter = True

'"Shoot".filter =("ShootID = " & oMyIDvalue) ***can't use form name directly here, just trying
'"Shoot".ApplyFilter = True
   
'Reload the form to show data
Oform2.reload

End Sub


Last edited by KCPhoto on Mon Sep 06, 2010 11:00 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
KCPhoto
General User
General User


Joined: 04 Sep 2010
Posts: 19
Location: RIchmond, KY

PostPosted: Mon Sep 06, 2010 10:58 am    Post subject: Reply with quote

Romke,

Sorry, I was posting at the same time you did.

Before starting on a new set of tools, I want to get this basic macro working. I need this database for my business to replace one I wrote years ago in MS Access. I'm not a programmer, I'm a photographer.

I know you want me to use those tools because they eliminate many of the lines of code required. I will install them when I have more time to refine my database.

Thanks,
Kenny
Back to top
View user's profile Send private message Visit poster's website
RPG
Super User
Super User


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

PostPosted: Mon Sep 06, 2010 11:02 am    Post subject: Reply with quote

Hello

First learn how to activate a filter for a form as document in which you work.
When you knew that then it is easy to do it in a just open form. A just open form returns a object what is the same as thiscomponent for the new document.

I think that you must better read the links you have found there all information is in the links you have already found so study them.

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


Joined: 04 Sep 2010
Posts: 19
Location: RIchmond, KY

PostPosted: Mon Sep 06, 2010 11:07 am    Post subject: Reply with quote

Well, the code would not work when using thiscomponent after opening the new form. This filter actually applied to the form from which I executed the macro. I tend to believe the errors are on my part and not a bug in the application.

Thanks,
Kenny
Back to top
View user's profile Send private message Visit poster's website
KCPhoto
General User
General User


Joined: 04 Sep 2010
Posts: 19
Location: RIchmond, KY

PostPosted: Mon Sep 06, 2010 11:13 am    Post subject: Reply with quote

I tried repeatedly to filter the form in design mode.

In the form properties box for the "Shoot" form I selected FIlter.

Then I entered:ClientID = then typed Client.CustomerID trying to refer to Client form that is open, but that didn't work.

All other efforts to filter from another form resulted in basing the form on a Query which prevented data entry and update.
For these reasons, I am trying to filter my form with a macro.

Thanks,
Kenny
Back to top
View user's profile Send private message Visit poster's website
KCPhoto
General User
General User


Joined: 04 Sep 2010
Posts: 19
Location: RIchmond, KY

PostPosted: Mon Sep 06, 2010 11:25 am    Post subject: Reply with quote

For the moment, I have abandoned my macro. I am using it to open the "Shoot" form only. I have gone into design mode of the shoot form and entered a filter in the form properties. Here is what I entered.

( "Shoot"."ClientID" = "Clients"."CustomerID" )

This will not work. The form opens but not to the current (or any) record and the record navigator shows no records. Can anyone help me with this form of filtering?

Kenny
Back to top
View user's profile Send private message Visit poster's website
RPG
Super User
Super User


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

PostPosted: Mon Sep 06, 2010 1:22 pm    Post subject: Reply with quote

Hello

Make first a filter in a normal way. Then try what you see.

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


Joined: 07 Jan 2010
Posts: 769

PostPosted: Mon Sep 06, 2010 4:20 pm    Post subject: Reply with quote

See if this helps sort things out.
_________________
Soli Deo gloria
Tutorial: avoiding data loss with Base + Splitting 'Embedded databases'
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
Goto page 1, 2  Next
Page 1 of 2

 
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