Forms and checkboxes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with one subform.
I would like that, if on the main form the field “open†has the value “0â€
the checkbox on the subform gets automatically checked.
Is that possible and if, how?
Thanks
Klaus
 
I set the Control source property of the box to the following:

=Forms!billsopenvalue!open

But it’s not automatically checked if the value in the field is “0â€
Do you have any other idea?
Thanks
Klaus
 
For text boxes

-1 = Checked
0 = Not checked

So if you put 0 in the main form box you will have a non-checked box on the
sub form.

Sorry but I assume that you are entering either -1 or 0 is this
correct. If not a little more info would be helpfull. You could use an
AfterUpdate event on the box on the main form to set the value of the box on
the sub form or other action but not sure what you're trying to do.
 
Hi Wayne
The main form field "open" is a result field from a query. If this field has
a positiv value the checkbox on the subform should be unchecked. If the main
form field "open" is showing the value "0" , the checkbox should be checked.
So, to use your explanation:
-1 = Checked
0 = Checked
+1 = not checked
Maybe this explanation helps a bid.
Thanks
Klaus
 
Private Sub open_AfterUpdate()
If (Forms!MainFormName!open > 0) Then
Me.SubFormName.SetFocus
Forms!MainFormName!SubFormName.Form!BoxOnSubFormName = -1
End If
End Sub



Change -
MainFormName
SubFormName
BoxOnSubFormName
to what they really are.

Note I have used Set Focus to enable to value to be set in the subform so
leave that there.

Hope this helps
 
Dear Wayne I've tried your code in the afterUpdate in in the sub-form as well
as in the main form.
Both trials are not bringing any result. I have the following code
If (Forms!billsopenvalue!open >0) Then
Me.paidbillshelp.SetFocus
Forms!billsopenvalue!paidbillshelp.Form!open = -1
End If

Do you have another solution?
Klaus
 
Having briefly scaned your code
your problem 'may' lie in your syntax

Forms!MainFormName!SubFormName.Form!BoxOnSubFormName = -1
does not equal
Forms!billsopenvalue!paidbillshelp.Form!open = -1

main problem in your code is you are using the subform syntax to referto a
control on your main form.

then again I might be totally wrong
 
Steve is right

you have written the code wrong. It should be


Forms!billsopenvalue!paidbillshelp.Form!NameOfBoxOnSubForm = -1


"NameOfBoxOnSubForm" needs changing to what it is

You place this code on the AfterUpdate of the control called "open" on the
main form. Delete all code from the subform check box. The control source
of this check box is the field in the table where you want to store the data
(0 or -1)
 
Note that the code is for open, which in this context is the name of the
control bound to the [Open] field. The field and the text box should have
different names so that both you and Access are less likely to be confused.
If the field is named [Open], try something like txtOpen as the text box
name. Another point is that Open is a reserved word in Jet (the database
engine underlying the user interface of the Access programs you create).
The use of reserved words for field and control names should be avoided.
However, if they are used they should be in square brackets. If you use
txtOpen as the name of the text box bound to the [Open] field, then the
After Update event for the *text box* would look something like this:

Private Sub txtOpen_AfterUpdate()
If Me.[Open] > 0 Then
Me.SubFormName.SetFocus
Forms!BillsOpenValue!PaidBillsHelp.Form![txtOpen] = -1
End If
End Sub

The code should work in the form's After Update event as well, and several
other places such as the subform control's Enter event. Note that when
referencing a control (or property) on the active form, you don't need to
use the Forms!etc. syntax. That is to say, your main form's record source
includes the field Open, and txtOpen is on the main form, so you can use the
Me.txtOpen syntax. The long syntax should work, but it is not necessary.
The subform is a separate object, so you need the longer syntax when
referencing it from another form (the main form).
 
Dear Wayne,
I tried your code and as well like underneath with ....open = 0
What am I doing wrong, my checkbox always is never checking automatically.

My code:
If (Forms!billsopenvalue!open = 0) Then
Me.paidbillshelp.SetFocus
Forms!billsopenvalue!paidbillshelp.Form!paid = -1
End If

Thanks
Klaus
 
Also, note that SubFormName in the code I suggested is the name of the
subform control. It may not have the same name as the subform. In form
design view (main form), click the subform once to select it, then click
View > Properties to verify the name (the top of the property sheet should
say Subform/Subreport). The SetFocus line needs to reference the subform
control.

BruceM said:
Note that the code is for open, which in this context is the name of the
control bound to the [Open] field. The field and the text box should have
different names so that both you and Access are less likely to be
confused. If the field is named [Open], try something like txtOpen as the
text box name. Another point is that Open is a reserved word in Jet (the
database engine underlying the user interface of the Access programs you
create). The use of reserved words for field and control names should be
avoided. However, if they are used they should be in square brackets. If
you use txtOpen as the name of the text box bound to the [Open] field,
then the After Update event for the *text box* would look something like
this:

Private Sub txtOpen_AfterUpdate()
If Me.[Open] > 0 Then
Me.SubFormName.SetFocus
Forms!BillsOpenValue!PaidBillsHelp.Form![txtOpen] = -1
End If
End Sub

The code should work in the form's After Update event as well, and several
other places such as the subform control's Enter event. Note that when
referencing a control (or property) on the active form, you don't need to
use the Forms!etc. syntax. That is to say, your main form's record source
includes the field Open, and txtOpen is on the main form, so you can use
the Me.txtOpen syntax. The long syntax should work, but it is not
necessary. The subform is a separate object, so you need the longer syntax
when referencing it from another form (the main form).

Amateur said:
Dear Wayne I've tried your code in the afterUpdate in in the sub-form as
well
as in the main form.
Both trials are not bringing any result. I have the following code
If (Forms!billsopenvalue!open >0) Then
Me.paidbillshelp.SetFocus
Forms!billsopenvalue!paidbillshelp.Form!open = -1
End If

Do you have another solution?
Klaus
 
Following on from Bruce's post.

If you can give the names of the forms and the controls then it would be
helpfull.

It should be a very simple operation but it seems that some of the
references in the code may be wrong (names)
 
Back
Top