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

Changing Text Box Text from a Macro
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
noneofdabove
General User
General User


Joined: 19 May 2008
Posts: 11

PostPosted: Mon May 26, 2008 5:58 pm    Post subject: Changing Text Box Text from a Macro Reply with quote

I have a macro that opens a form and changes the value of a text box. The problem that I am having is that it works if the text box is not bond to any thing but if I bond the text box it will not change the Text. Is there something differently I need to do if it is bonded?

Sub onClickNewSite ( oEvent as Variant )
Dim oForm as Variant
Dim thisForm as Variant : thisForm = oEvent.Source.getModel().getParent()
Dim oControl

oForm = OpenForm ( oEvent, "Site" )
oControl = oForm.getByName("txtCustomerName").getText
oControl.Text = thisForm.getByName("txtName").Text

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: Tue May 27, 2008 12:03 pm    Post subject: Reply with quote

Hello
Quote:

I have a macro that opens a form and changes the value of a text box. The problem that I am having is that it works if the text box is not bond to any thing but if I bond the text box it will not change the Text. Is there something differently I need to do if it is bonded


This looks me normal.
If the text must go to the database look : http://www.oooforum.org/forum/viewtopic.phtml?t=71724&sid=ad51091407a64fa7399b68a61bf5c13a

If the problem is some thing else make clear what you expect

I hope it helps you

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


Joined: 19 May 2008
Posts: 11

PostPosted: Tue May 27, 2008 7:54 pm    Post subject: Reply with quote

Hopefully this will clarify what I am wanting to do. My database has customers in which each customer has multiple sites. From my customer form, the form that I am opening will create a new site for the customer. I am trying to set the text box to the customer name from the calling form. This same text box is bound to the Site table, which contains the column CustomerName. It is not allowing me to change the value in this text box. If I edit the Site form so that the text box is not bound to any column it works which tells me that I have access to the text box but that there must be another way for me to change the field if bound to a table. I have printed out the DBG info but I am unsure of what to use for bound OEditModels. The thread that you gave me shows and updateString method but when I tried this it gives a method not found error so I am assuming that there is something different I need to use for text boxes. I am new to OpenOffice and I am still trying to make sense of the API so any help or explanation is much appreciated.
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 May 28, 2008 12:03 am    Post subject: Reply with quote

Hello

Maybe you try to edit a view or query. You can not edit a text field if it is a part of a view or query.

Look for information http://www.oooforum.org/forum/viewtopic.phtml?t=71733&sid=8953166b92d7e754951beffc80ea0eef

I hope it helps you.
Romke
Back to top
View user's profile Send private message
noneofdabove
General User
General User


Joined: 19 May 2008
Posts: 11

PostPosted: Thu May 29, 2008 5:25 pm    Post subject: Reply with quote

How do I know if its part of a view? Is it if the text box or form is derived from an SQL statements? If this is the case, then my form is derived from a table. I don't know if this matters but I am using Base as a front end for an MS Access database.
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: Thu May 29, 2008 11:21 pm    Post subject: Reply with quote

Hello

1) you want change a table in database?
yes : read further
no : I don't understand you. And maybe we stop
2) Can you make the change by hand ?
yes it is a real table and the error is in your program code
no maybe it is view or query wich you can not edit
maybe MS acces gives the problem I don't anything about MS acces

3) How do you know what the base is of your form
use the code
Code:

print  oForm command  rem for the form you want change



I don't if MS access gives or can give problem. Maybe it is better you read the sticky links who are for this kind of problems.

I hope it helps you
Romke
Back to top
View user's profile Send private message
noneofdabove
General User
General User


Joined: 19 May 2008
Posts: 11

PostPosted: Mon Jun 02, 2008 6:48 pm    Post subject: Reply with quote

I used the print command to print the oControl.Text and here is what happen. Sometimes the text box would change. The print would always show the information that I am trying to place in the text box, but never did it place the information in the database. I also tried to change a text box on the calling form and it would change the information in the box but never place it in the database. Is there another way to change the text box? I tried using oControl.setString("someString") and it did not work.
Back to top
View user's profile Send private message
noneofdabove
General User
General User


Joined: 19 May 2008
Posts: 11

PostPosted: Mon Jun 02, 2008 6:49 pm    Post subject: Reply with quote

Also, I can manually change the text boxes and the information does change in the database.
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: Tue Jun 03, 2008 2:04 am    Post subject: Reply with quote

Hello


I have modified the macro so I expect it is working. Some thing you must change. If there is an other error come back with questions.The different is that only move the value in the text field does not move it in the database. I have only changed that.

I hope it helps you
Romke



Code:

Sub onClickNewSite ( oEvent as Variant )
Dim oForm as Variant
Dim thisForm as Variant
thisForm = oEvent.Source.getModel().getParent()
Dim oControl
oForm = OpenForm ( oEvent, "Site" ) ' I don't understand what this code is doing
oControl = oForm.getByName("txtCustomerName").getText  rem This code is not change and i assumed it takes text you need
'next line is outcomment
'oControl.Text = thisForm.getByName("txtName").Text rem I think you don't need it more

'You must give you own field name' I can't  know it
'I think that oControl give the value you need

dim nIndexDate rem variable for field you whant change
nIndexDate=thisForm.findColumn("your fieldname") rem take indexnumber the date field you must give your name
thisForm.updateString(nIndexDate, oControl) rem Bring value in field of record
Back to top
View user's profile Send private message
noneofdabove
General User
General User


Joined: 19 May 2008
Posts: 11

PostPosted: Tue Jun 03, 2008 7:22 pm    Post subject: Reply with quote

I am getting a sequence error on the updateString method. I changed the code to hopefully make it more readably.

Sub onClickNewSite ( oEvent as Variant )
'Open Site Form for Addition
Dim newForm as Variant : newForm = OpenForm ( oEvent, "Site" ) 'opens new form "Site"
Dim thisForm as Variant : thisForm = oEvent.Source.getModel().getParent() 'calling form
Dim oControl
Dim nString as String : nString = thisForm.getByName("txtName").Text 'text on calling form being update on new form
Dim nIndex

'oControl = newForm.getByName("txtCustomerName")
'oControl.Text = nString
nIndex = newForm.findColumn("txtCustomerName")
'newForm.updateString(nIndex,nString)

End Sub
[/code]
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 Jun 04, 2008 12:04 am    Post subject: Reply with quote

Hello
I have only change in the end a little in the code
1) I have insert : newForm.moveToInsertRow 'This makes a new reocrd
2) I have uncomment this line: newForm.updateString(nIndex,nString) 'this update the field in that record
3)I have insert newForm.InsertRow 'this moves the record to the database

I did not understand that it was a complete new record. Maybe you can get an error that you not give a primary index or other thing what that record needs. I can only see this part of you database.
I do me remember the first time I was playing with a table and trying to make a new record I had the same problems. What is the good code. I cost me also a lot of time.

I hope you are finish now with the code. If it is not complete correct come with other questions.
Romke




Code:

Sub onClickNewSite ( oEvent as Variant )
'Open Site Form for Addition
Dim newForm as Variant : newForm = OpenForm ( oEvent, "Site" ) 'opens new form "Site"
Dim thisForm as Variant : thisForm = oEvent.Source.getModel().getParent() 'calling form
Dim oControl
Dim nString as String : nString = thisForm.getByName("txtName").Text 'text on calling form being update on new form
Dim nIndex

'I assume you want make a new record

newForm.moveToInsertRow 'This makes a new reocrd
'oControl = newForm.getByName("txtCustomerName")
'oControl.Text = nString
nIndex = newForm.findColumn("txtCustomerName")
newForm.updateString(nIndex,nString) 'this update the field in that record
newForm.InsertRow 'this moves the record to the database

End Sub
Back to top
View user's profile Send private message
noneofdabove
General User
General User


Joined: 19 May 2008
Posts: 11

PostPosted: Thu Jun 05, 2008 2:59 am    Post subject: Reply with quote

newForm.moveToInsertRow() is giving me a function sequence error, which is a SQLException. What does this error mean? Also, if I don't have a table control on the form, will newForm.findColumn work? I am errors for it but I tried using it to find a text box thisForm and it gave me an error.
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: Thu Jun 05, 2008 3:42 am    Post subject: Reply with quote

Hello

Quote:
Also, if I don't have a table control on the form, will newForm.findColumn work

I think it does not work. That instruction assume you have a table where you want to move the data in.
Not only the instruction assumes that. You also want move the data in a table.
If the form has not a table to with it is bound You can not move the data in the table.

Maybe it is good that we both have the same idea what you mean with "table control". For me means it that newForm is bound to a table.

this instruction with Newform assume there is a table
newForm.moveToInsertRow
newForm.findColumn("txtCustomerName")
newForm.updateString(nIndex,nString) newForm.InsertRow



I hope you comes closer to a solution. For me it is difficult to see what the problem really is. But this is a good way of learning how this is working.
I don't know what you know. I do talk about instruction with newForm. That is not the good word for it. The correct word is methods and properties of the object of Newform.

How better you understand what object programming is how better it will work. It have takes for me a long time for I understand it. I do this only for home use I'm not a professional

I hope it helps you
Romke
Back to top
View user's profile Send private message
noneofdabove
General User
General User


Joined: 19 May 2008
Posts: 11

PostPosted: Fri Jun 06, 2008 2:27 am    Post subject: Reply with quote

By table control, I am mean that the text boxes are a control, like list boxes and combo boxes are controls. A table control is control that lookes like a spreadsheet, or tables in base. Tables have columns and rows in them. The columns could be text boxes, list boxe, etc. The text boxes on my forms are not in a table there are just attached to a the form. The forms are bound to tables and the text boxes are bound to fields in those tables. newForm.findcolumn works does not give any errors but if I try thisForm.findcolumn it does. I just wonder if it does not work because these text boxes are not in a table control. If I do thisForm.moveToInsertRow it works but newForm.moveToInsertRow is giving a "Function Sequence Error". If I comment out newForm.moveToInsertRow it gives me the same error on newForm.updateString. I dont know if is because I am passing back the new form with newForm=OpenForm(oEvent,"Site"). I am to get control of the text boxes from that form with newForm.getByName("control_name ") but it just does allow me to change the text. I understand object programming and I have searching for through the methods and API, and trying different things but I have not found anything that works. I am finding that the API is kind of hard to search through and not easy for me to read.
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: Fri Jun 06, 2008 6:23 am    Post subject: Reply with quote

Hello

You explanation of the table control is correct. I don't look to the table control,the grid.
I look only to the form and the form is connect to the database table.with the form object you can access the database table and the controls how they are on the screen. You want change the database so I look only to the form. I hope so I have explain why I do as I do.

I have read it and for me it is also complicated.
I have made a piece of code. I you execute it on you computer maybe we will learn more about the reason.

The next code can tell us more
Code:

dim What
   What= "thisform  " & thisform.implementationname & chr(13)
   What = What & "Newform   " & Newform.implementationname & chr(13)
   What = What & "thisform  " &   thisform.command & chr(13)
   What = What & "Newform    " &   Newform.command & chr(13)
msgbox What
   end

forms have to be of the kind: "com.sun.star.comp.forms.ODatabaseForm"
the command should be a table or a simple query not a query with more tables.

I have read your complete post. And I think we have make no error in the code.

Quote:

newForm.findcolumn works does not give any errors but if I try thisForm.findcolumn it does. I just wonder if it does not work because these text boxes are not in a table control.

Do I understand this corect:
newForm.findcolumn give no error
thisForm.findcolumn gives an eror.

The table control or no table control is no reason for an error

It give more problems as I had expected but we both learn about it.

What I do not know are there two writer documents?

Quote:

Dim newForm as Variant : newForm = OpenForm ( oEvent, "Site" ) 'opens new form "Site"

As you you write newform.findcolum gives no problem, but we cannot make a new record.
It look to me there are two possibilities
1) you have no write access to it.
2) It is not a real table.
With the above code I hope to find information about it.


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
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