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

Enable a textbox when a checkbox is ticked

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


Joined: 07 Jun 2008
Posts: 4

PostPosted: Sat Jun 07, 2008 9:29 am    Post subject: Enable a textbox when a checkbox is ticked Reply with quote

I am trying to make a textbox enable itself when a checkbox is checked.

For example, when the checkbox "chkActionTaken" is checked,
I would want the textbox "datDateActionTaken" to enable itself.
Conversely, when the "chkActionTaken" is unchecked,
the textbox "datDateActionTaken" would be disabled and left blank.

How do I do this using macro?

Another question, similarly, is it possible to disable another checkbox when one checkbox is checked?
The use of a option (radio) button is not suitable in this case.
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: Sat Jun 07, 2008 10:31 am    Post subject: Reply with quote

Hello
Maybe this can help you

Code:

sub Checkbox_activeer_textfield '(oevent as object)
dim beginform as object
dim   oCheckBox as object
dim oTextBox
beginform=ThisComponent.Drawpage.Forms.getByName("NameOfForm")
oCheckBox=beginform.getByName("CheckBox")
oTextBox = beginform.getByName("TextBox")
if cbool (oCheckBox.currentvalue) then
   oTextBox.Enabled=true
   else
   oTextBox.Enabled=false
   end if
end sub


romke
Back to top
View user's profile Send private message
tjmj
Newbie
Newbie


Joined: 07 Jun 2008
Posts: 4

PostPosted: Sat Jun 07, 2008 11:29 am    Post subject: Reply with quote

thank you for your reply.

I still face a problem maybe because i am using a subform to do so.
I get an error saying about NoSuchElementException.
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: Sat Jun 07, 2008 1:30 pm    Post subject: Reply with quote

Hello
If you use a subform you have to use this ode
Code:
subform=beginform.getByName("NameOfForm")


This same can you use for more subforms and if you go deeper. Think that the control must be bound to the good form.

Romke
Back to top
View user's profile Send private message
tjmj
Newbie
Newbie


Joined: 07 Jun 2008
Posts: 4

PostPosted: Sat Jun 07, 2008 7:03 pm    Post subject: Reply with quote

Hello RPG

I am not very efficient in macros. And you have solved my problem like a charm.
Thank you very much.
Back to top
View user's profile Send private message
tjmj
Newbie
Newbie


Joined: 07 Jun 2008
Posts: 4

PostPosted: Sat Jun 07, 2008 8:11 pm    Post subject: Reply with quote

I have another question.

How do you do it if it was a radio button instead of a checkbox?
Sorry, I am very poor in macros.
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: Sun Jun 08, 2008 5:30 am    Post subject: Reply with quote

Hello

I have also made the code code for radio button.

For the checkbox I have made two subs. One you have to take care of names, the other one names are not so important more only for the text box. The last one you can not execute in edit mode.
I hope it helps you
Romke




Code:
option explicit
REM  *****  BASIC  *****
dim beginform as object
dim oCheckBox as object
dim oTextBox
dim oRadioButton as object


Sub Main
concheckbox
End Sub

sub Checkbox_activeer_textfield (oevent as object)
Checkbox_activeer_textfield_new oevent
end sub

sub Checkbox_activeer_textfield_old
initformulier
if cbool (oCheckBox.currentvalue) then
   oTextBox.Enabled=true
   else
   oTextBox.Enabled=false
   end if
end sub


sub Checkbox_activeer_textfield_new (oevent as object)
' You can use this instruction if the control are in the same form or same subform
oCheckBox=oevent.source.model
oTextBox=oCheckBox.parent.getByName("TextBox")

if cbool (oCheckBox.currentvalue) then
   oTextBox.Enabled=true
   else
   oTextBox.Enabled=false
   end if
end sub





sub test1
' bound this to an an event
initformulier
'oradioknop.RefValue="On" 'You can use every value
oTextBox.Enabled=true
end sub

sub test2
' bound this to an an event
initformulier
'oradioknop.RefValue="Off" 'If you want you can change the value
oTextBox.Enabled=false
end sub


sub test3
'I have made three but change it
initformulier
'oradioknop.RefValue="No"
oTextBox.Enabled=true
end sub

sub initformulier
beginform=ThisComponent.Drawpage.Forms.getByName("NameOfForm")
'subform=ThisComponent.getByName("name_of_subform")
oCheckBox=beginform.getByName("CheckBox")
oTextBox = beginform.getByName("TextBox")
oRadioButton=beginform.getByName("RadioGroup1")
end sub
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