make field invisable

F

fishqqq

I have a report with 3 fields in it
[checkbox 1]
[textfield 1]
[textfield 2]

what i'm trying to do is have the two text field's properties set to
invisable or visable depending on if the checkbox is checked or not.

eg
[checkbox1]= yes
then [textfield1] & [textfield 2] = visable

[checkbox1]=no
then [textfield1] & textfield 2] = not visable

Can someone tell me how to begin to code this?

Any help is greatly appreciated.
tks
 
R

Rob Parker

In the Format event of the section of the report where the controls are
located:
textfield1.visible = checkbox1
textfield2.visible = checkbox1

Rob
 
F

fishqqq

In the Format event of the section of the report where the controls are
located:
    textfield1.visible = checkbox1
    textfield2.visible = checkbox1

Rob

Thanks Rob, but i'm still confused.
when I go to the EVENT tab of the detail section of the report (which
has the fields i want to hide or show) I see an "ON FORMAT" property.
And when I paste:

Airline.visible = MLABEL#1 (where Airline = the
field name and MLABEL#1 = the checkbox name)

I get an error message stating: "Cannot find the object Airline"

I'm not sure if I'm pasting this in the right section or not. It makes
sense to me to paste this somewhere on the actual field - but I can't
figure out where.

Also i will have 11 controls in total that I will like to either hide
or show depending on the checkbox being checked or not (all 11
controls = 1 printed label), and on the report I would like to have up
to 6 labels in total (for a total of 66 controls all visable or not
depending on their coresponding checkboxes)

the fields that make up the 1st label are:
[Airline]
[Text5]
[Text8]
[label11]
[Origin Airport]
[label27]
[Dest Airport]
[Label28]
[qAWBLabels]
[Label7]
[Text6]

Can you please tell me how to go about this?
thanks
Steve



I have a report with 3 fields in it
[checkbox 1]
[textfield 1]
[textfield 2]
what i'm trying to do is have the two text field's properties set to
invisable or visable depending on if the checkbox is checked or not.
eg
[checkbox1]= yes
then [textfield1] & [textfield 2] = visable
[checkbox1]=no
then [textfield1] & textfield 2] = not visable
Can someone tell me how to begin to code this?
Any help is greatly appreciated.
tks
 
R

Rob Parker

Seems that my newsreader isn't wanting to mark previous message text with >
this time around - reply to latest question below:

In the Format event of the section of the report where the controls are
located:
textfield1.visible = checkbox1
textfield2.visible = checkbox1

Rob

Thanks Rob, but i'm still confused.
when I go to the EVENT tab of the detail section of the report (which
has the fields i want to hide or show) I see an "ON FORMAT" property.
And when I paste:

Airline.visible = MLABEL#1 (where Airline = the
field name and MLABEL#1 = the checkbox name)

I get an error message stating: "Cannot find the object Airline"

I'm not sure if I'm pasting this in the right section or not. It makes
sense to me to paste this somewhere on the actual field - but I can't
figure out where.

Also i will have 11 controls in total that I will like to either hide
or show depending on the checkbox being checked or not (all 11
controls = 1 printed label), and on the report I would like to have up
to 6 labels in total (for a total of 66 controls all visable or not
depending on their coresponding checkboxes)

the fields that make up the 1st label are:
[Airline]
[Text5]
[Text8]
[label11]
[Origin Airport]
[label27]
[Dest Airport]
[Label28]
[qAWBLabels]
[Label7]
[Text6]

Can you please tell me how to go about this?
thanks
Steve

REPLY:

The code I gave you is VBA code, and needs to be entered into the code
module for the object - in this case, your report - via the VBA editor. You
get to this by selecting the On Format property (for the section of the
report), and double-clicking in the empty field; when you do so, [Event
Procedure] will appear, together with an ellipsis (...) to the right of the
field. Click on the ellipsis to open the VBA editor, with a subroutine
"stub" consisting on three lines, such as this:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

End Sub

Enter the code statements, each on a single line, between the opening
"Private Sub ..." and closing "End Sub" lines for this event.

A few other points:

The statements I gave did not have [ ] around the control names. This is
acceptable if the names have no spaces, but the [ ] delimiters are required
if your control names have spaces in them (as some do).

Your list of controls does not include any control named either [checkbox1]
or [checkbox 1] (you had both in your original post - I assumed the first).
The right-hand side of the statements must be the name of the control whose
value you are wanting to check. If it's a checkbox - which can only have
values of Yes (True) or No (False) - under the covers, these are -1 and 0
respectively - you can use that boolean value directly in the statement to
set the visibility of other controls. So:
[textfield1].visible = [checkbox1]
[textfield2].visible = [checkbox1]
is equivalent - but much easier to enter - to:
If [checkbox1]= True then
[textfield1].visible = True
[textfield2].visible = True
Else
[textfield1].visible = False
[textfield2].visible = False
End If

You'll need a statement for each control in the report section whose
visibility you're wanting to set.

There are other - probably more efficient - ways to do this, involving use
of the tag property for controls and code to loop through multiple controls
and set the visibility depending on both the tag property and another
control's value, but I won't complicate things to much for you at this time.

Finally, consider giving your controls more meaningful names, rather than
[Text6] and [Label7], for example. It will make life much easier when you
come to revisit your code.

HTH,

Rob

I have a report with 3 fields in it
[checkbox 1]
[textfield 1]
[textfield 2]
what i'm trying to do is have the two text field's properties set to
invisable or visable depending on if the checkbox is checked or not.
eg
[checkbox1]= yes
then [textfield1] & [textfield 2] = visable
[checkbox1]=no
then [textfield1] & textfield 2] = not visable
Can someone tell me how to begin to code this?
Any help is greatly appreciated.
tks
 
J

John W. Vinson

Thanks Rob, but i'm still confused.
when I go to the EVENT tab of the detail section of the report (which
has the fields i want to hide or show) I see an "ON FORMAT" property.
And when I paste:

You need to click the ... icon next to the event line; this will open the VBA
window where you can edit the code. It doesn't go in the little box, which
should show [Event Property].
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top