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

Joined: 07 Jun 2008 Posts: 4
|
Posted: Sat Jun 07, 2008 9:29 am Post subject: Enable a textbox when a checkbox is ticked |
|
|
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 |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Sat Jun 07, 2008 10:31 am Post subject: |
|
|
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 |
|
 |
tjmj Newbie

Joined: 07 Jun 2008 Posts: 4
|
Posted: Sat Jun 07, 2008 11:29 am Post subject: |
|
|
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 |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Sat Jun 07, 2008 1:30 pm Post subject: |
|
|
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 |
|
 |
tjmj Newbie

Joined: 07 Jun 2008 Posts: 4
|
Posted: Sat Jun 07, 2008 7:03 pm Post subject: |
|
|
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 |
|
 |
tjmj Newbie

Joined: 07 Jun 2008 Posts: 4
|
Posted: Sat Jun 07, 2008 8:11 pm Post subject: |
|
|
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 |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Sun Jun 08, 2008 5:30 am Post subject: |
|
|
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 |
|
 |
|