| View previous topic :: View next topic |
| Author |
Message |
Gianluca Bardi General User

Joined: 08 Sep 2003 Posts: 9 Location: Via delle Panche 181 I-50141 Firenze - Italy
|
Posted: Tue Dec 09, 2003 9:49 pm Post subject: TextBox connected to database |
|
|
I have a form connected to a database table. In the form there is a textbox in which I need to write the content by a macro by the following instruction:
oCtl2.Text = "whateveryoulike"
Actually after running the macro, the textbox in the form shows "whateveryoulike". The problem is that even if I try to save the situation into the database table by clicking the SAVE icon no effect in the table is observed. The content of the field bound to the textbox doesn't contain "whateveryoulike" but remains unchanged as it was before running the macro. _________________ Gianluca Bardi |
|
| Back to top |
|
 |
dfrench Moderator

Joined: 03 Mar 2003 Posts: 1605 Location: Wellington, New Zealand
|
Posted: Wed Dec 10, 2003 5:48 am Post subject: |
|
|
The control needs to have the focus before it detects the change and enables the 'save' of the changed data. Thanks to thingkcp and http://www.oooforum.org/forum/viewtopic.php?t=1046&highlight=mysql
the following code takes you to the point at which the change can be saved to the database
| Code: | Sub Main
oController = ThisComponent.CurrentController
oForm = ThisComponent.drawpage.forms.GetByName("Standard")
rem This assumes that the form has the default name "Standard"
cControl = oForm.GetByName("TextBox")
rem this is the control model
oControlView = oController.GetControl(cControl)
rem this is the control view - the object you want to work with
oControlView.SetFocus 'sets the focus
cControl.Text = "anything" 'changes the text in the box
' now you can explicitly save (see change in save icon on navigation bar)
End Sub |
|
|
| Back to top |
|
 |
g.bardi Guest
|
Posted: Wed Dec 10, 2003 11:46 pm Post subject: TextBox connected to database |
|
|
| It works perfectly, thanks a lot. |
|
| Back to top |
|
 |
Gabriel123 Newbie

Joined: 14 Jan 2008 Posts: 2
|
Posted: Thu Jan 17, 2008 7:33 am Post subject: get the focus |
|
|
This is a very nice snippet...I have a form with about 20 fields that are macro filled. How can i get the focus on each of them to save them into the table?
Any Way? Thanks in advance! |
|
| Back to top |
|
 |
Evgenych General User

Joined: 03 Jan 2008 Posts: 9
|
Posted: Sun Jan 27, 2008 6:52 am Post subject: |
|
|
I use commit() method of control, when change controls programmaticaly
sub onCheckbox ()
oForm = ThisComponent.DrawPage.Forms.getByName("MainForm")
oCheckBox = oForm.GetByName("CheckBox")
oTxt = oForm.GetByName("txtNaryad_zakaz")
if oCheckBox.CurrentValue = 1 then
oTxt.Value = 1
oTxt.commit()
else
oTxt.Value = nul
oTxt.commit()
end if
end sub |
|
| Back to top |
|
 |
|