Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hide labels

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
I am trying to hide a label if the value of a field equals a certain criteria.

I have the following code which is not working:
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.AddressType.value = "Bank of Scotland Plc" Then
Me.Label14.Visible = True
End If
End Sub

Any ideas?
 
What about:
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.AddressType.value = "Bank of Scotland Plc" Then
Me.Label14.Visible = True
ELSE
Me.Label14.Visible = False
End If
End Sub
 
No that doesnt seem to work. The label is still always showing for each record.
 
Maybe try to add a new sub for the print event? Copy and paste below, into the ON PRINT event. Don't remove the Format code you already have.

Code:
Private Sub Detail_Print(Cancel As Integer, FormatCount As Integer)
If Me.AddressType.value = "Bank of Scotland Plc" Then
Me.Label14.Visible = True
ELSE
Me.Label14.Visible = False
End If
End Sub
 
thanks for this. how would I hide/show a field if addresstype = Bank of Scotland plc?
 
primagic,
Is this a different question?

You don't hide/show a "field". I think you meant "control".

Do you want to hide a text box vs. the label you wanted to hide earlier?

Did any of the earlier suggestions work for hiding the label/caption?


Duane
Hook'D on Access
MS Access MVP
 
Sorry I am jumping ahead.

Your code work to hide a label. Thank you.

Now I need to show some fields with the same criteria

Thanks
 
How are ya primagic . . .
In your post origination you say:
primagic said:
[blue]I am trying to [purple]hide a label[/purple] if the value of a field equals a certain criteria.[/blue]
However in your initial code show the label if equality in the if statement s achieved:
Code:
[blue]If Me.AddressType.value = "Bank of Scotland Plc" Then
   Me.Label14.Visible = [purple][b]True[/b][/purple]
End If[/blue]
My point is ... this is the opposite of what you asked for. And as [blue]sxschech[/blue] replied with the correct code (true/false just needed to be reversed), I don't see how you had a problem with this as I performed a simulation in 2003 which worked just fine. Code should be:
Code:
[blue]Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
   If Me.AddressType.value = "Bank of Scotland Plc" Then
      Me.Label14.Visible = [purple][b]False[/b][/purple]
   ELSE
      Me.Label14.Visible = [purple][b]True[/b][/purple]
   End If
End Sub[/blue]
What version access?

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
The code should work. It may be a situation where primagic is not viewing the Print Preview or printed report. Also, I believe the AddressType field must be bound to a control in order to work.

Duane
Hook'D on Access
MS Access MVP
 
dhookom . . .

Agreeded. Its just that the thread continued on as if what should work ... didn't. [surprise]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Hi,

This code works:

Code:
=IIf([AddressType] = "Bank of Scotland Plc","Label Text","")

This code doesnt work:

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
   If Me.AddressType.value = "Bank of Scotland Plc" Then
      Me.Label14.Visible = False
   ELSE
      Me.Label14.Visible = True
   End If
End Sub

AddressType is bound to a field in the recordsource.

What I am trying to do now is extend it to hide fields and possibly a subreport.

The report displays totals of fees, vat and so on for each bank, however I need to split these totals in fee type for eg. if the bank is Bank of Scotland plc. So I thought hiding fields/subreports would be the best option.

The report is like:

AddressType Fees VAT Total
Bank of Scotland 50 50 100
Bank of America 100 20 120
Bank of Brazil 10 10 20

What I am trying to achieve is:

AddressType Fees VAT Total
Bank of Scotland 50 50 100
Residential 25 25 50
Commercial 25 25 50
Bank of America 100 20 120
Bank of Brazil 10 10 20
 
Primagic,
You haven't told use which view you are opening the report in.
What have you done to debug the code? Are you sure it is running? Have you tried any debug.print statements?

The solution I suggested won't work with subreports. The code solution will work if you apply it correctly.

Is the address type a lookup field?

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top