Hide Fields on report

S

SPK

Hi all,
I want to hide some fileds based on the value of the other field.
I have tried the following code but not of any use. can you point out
where exactly I'm going wrong
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Result_Incub = "Positive" Then
Me.Sample_Analysis_Dt.Visible = False
Me.Result.Visible = False
Else
Me.Sample_Analysis_Dt.Visible = True
Me.Result.Visible = True
End If
End Sub
 
A

Allen Browne

Code looks okay, so something else must be happening.

What version of Access is this? And what view? In Access 2007, the report
events don't fire in Report view or Layout view, so the code won't run. Try
Print Preview instead.

If that is not the issue, ask Access what's going on.
Add the line:
Debug.Print (Me.Result_Incub = "Positive")
Then open the report, open the Immediate Window (Ctrl+G), and see if what
came out matches the records in the report. It might help to also add the
primary key so you can see which record the answers apply to. Perhaps:
Debug.Print Me.ID, (Me.Result_Incub = "Positive")

In general, it is more efficient to print a null than to hide and unhide
controls with code. You may be able to avoid the code by setting the Control
Source of a text box like this:
=IIf([Result_Incub] = "Positive", Null, [Sample_Analysis_Dt])
If you do this, change the Name property of the text box as well.
Access gets confused if the control's Name is the same as a field, but it is
bound to something else.
 
S

SPK

Hi Allen,
I'm using Access 2000 version. I have also tried the following code in the
onPrint property of the details section

Me.[Sample_Anal_Dt].visible = Not(Mid([Result],1,1)="P")
--
SPK


Allen Browne said:
Code looks okay, so something else must be happening.

What version of Access is this? And what view? In Access 2007, the report
events don't fire in Report view or Layout view, so the code won't run. Try
Print Preview instead.

If that is not the issue, ask Access what's going on.
Add the line:
Debug.Print (Me.Result_Incub = "Positive")
Then open the report, open the Immediate Window (Ctrl+G), and see if what
came out matches the records in the report. It might help to also add the
primary key so you can see which record the answers apply to. Perhaps:
Debug.Print Me.ID, (Me.Result_Incub = "Positive")

In general, it is more efficient to print a null than to hide and unhide
controls with code. You may be able to avoid the code by setting the Control
Source of a text box like this:
=IIf([Result_Incub] = "Positive", Null, [Sample_Analysis_Dt])
If you do this, change the Name property of the text box as well.
Access gets confused if the control's Name is the same as a field, but it is
bound to something else.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

SPK said:
Hi all,
I want to hide some fileds based on the value of the other field.
I have tried the following code but not of any use. can you point out
where exactly I'm going wrong
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Result_Incub = "Positive" Then
Me.Sample_Analysis_Dt.Visible = False
Me.Result.Visible = False
Else
Me.Sample_Analysis_Dt.Visible = True
Me.Result.Visible = True
End If
End Sub
 
A

Allen Browne

What did you learn from the Debug.Print results?

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

SPK said:
Hi Allen,
I'm using Access 2000 version. I have also tried the following code in the
onPrint property of the details section

Me.[Sample_Anal_Dt].visible = Not(Mid([Result],1,1)="P")
--
SPK


Allen Browne said:
Code looks okay, so something else must be happening.

What version of Access is this? And what view? In Access 2007, the report
events don't fire in Report view or Layout view, so the code won't run.
Try
Print Preview instead.

If that is not the issue, ask Access what's going on.
Add the line:
Debug.Print (Me.Result_Incub = "Positive")
Then open the report, open the Immediate Window (Ctrl+G), and see if what
came out matches the records in the report. It might help to also add the
primary key so you can see which record the answers apply to. Perhaps:
Debug.Print Me.ID, (Me.Result_Incub = "Positive")

In general, it is more efficient to print a null than to hide and unhide
controls with code. You may be able to avoid the code by setting the
Control
Source of a text box like this:
=IIf([Result_Incub] = "Positive", Null, [Sample_Analysis_Dt])
If you do this, change the Name property of the text box as well.
Access gets confused if the control's Name is the same as a field, but it
is
bound to something else.

SPK said:
Hi all,
I want to hide some fileds based on the value of the other field.
I have tried the following code but not of any use. can you point out
where exactly I'm going wrong
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Result_Incub = "Positive" Then
Me.Sample_Analysis_Dt.Visible = False
Me.Result.Visible = False
Else
Me.Sample_Analysis_Dt.Visible = True
Me.Result.Visible = True
End If
End Sub
 
S

SPK

Hi Allen,

Problem is sorted out. Thanks for the timely help.
--
SPK


Allen Browne said:
What did you learn from the Debug.Print results?

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

SPK said:
Hi Allen,
I'm using Access 2000 version. I have also tried the following code in the
onPrint property of the details section

Me.[Sample_Anal_Dt].visible = Not(Mid([Result],1,1)="P")
--
SPK


Allen Browne said:
Code looks okay, so something else must be happening.

What version of Access is this? And what view? In Access 2007, the report
events don't fire in Report view or Layout view, so the code won't run.
Try
Print Preview instead.

If that is not the issue, ask Access what's going on.
Add the line:
Debug.Print (Me.Result_Incub = "Positive")
Then open the report, open the Immediate Window (Ctrl+G), and see if what
came out matches the records in the report. It might help to also add the
primary key so you can see which record the answers apply to. Perhaps:
Debug.Print Me.ID, (Me.Result_Incub = "Positive")

In general, it is more efficient to print a null than to hide and unhide
controls with code. You may be able to avoid the code by setting the
Control
Source of a text box like this:
=IIf([Result_Incub] = "Positive", Null, [Sample_Analysis_Dt])
If you do this, change the Name property of the text box as well.
Access gets confused if the control's Name is the same as a field, but it
is
bound to something else.

Hi all,
I want to hide some fileds based on the value of the other field.
I have tried the following code but not of any use. can you point out
where exactly I'm going wrong
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Result_Incub = "Positive" Then
Me.Sample_Analysis_Dt.Visible = False
Me.Result.Visible = False
Else
Me.Sample_Analysis_Dt.Visible = True
Me.Result.Visible = True
End If
End Sub
 

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