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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to hide a label in a report for specific records 2

Status
Not open for further replies.

Wantabie

Programmer
Apr 29, 2004
72
0
0
US
I have a similar question as thread 703-893155. I have a report that uses a query as it's recordsource and I would like to know how to hide a label, that when a field has a value of -1, the label is displayed and when it's value is 0, it is not displayed. The field I am wanting to read is a yes/no field. I have gotten my code to work most of the way, that is, it reads the desired records, but it is not displaying the label when requested. Can someone help?

My code is
Code:
[blue]Private Sub[/blue] Report_Open([red]Cancel[/red] as integer)
Dim db As Database
Dim rst As Recordset
Dim varBookmark As Variant

Set db = CurrentDb()
Set rst = db.OpenRecordset("tblTicketingSystem", _ dbOpenDynaset)

rst.MoveLast
rst.MoveFirst

Do Until rst.EOF
     varBookmark = rst.Bookmark
     if rst!Chronic = True Then
          Me.lblChronic.Visible = True
     Else Me.lblChronic.Visible = False
     End If
     rst.MoveNext
Loop
rst.Close
Set rst = Nothing
[blue]End Sub[/blue]

Am i on the right track?

Many thanks,

Wantabie
 
Humor me (because I designed a form that had a similar requirement).

What happens when you swap the True/False clauses? So your code would instead look like this:

Code:
Private Sub Report_Open(Cancel as integer)
Dim db As Database
Dim rst As Recordset
Dim varBookmark As Variant

Set db = CurrentDb()
Set rst = db.OpenRecordset("tblTicketingSystem", _ dbOpenDynaset)

rst.MoveLast
rst.MoveFirst

Do Until rst.EOF
     varBookmark = rst.Bookmark
     if rst!Chronic = True Then
          Me.lblChronic.Visible = False
     Else Me.lblChronic.Visible = True
     End If
     rst.MoveNext
Loop
rst.Close
Set rst = Nothing
End Sub

Does that work? Because if it does, I can't explain why. I just know it worked for me when I did a form that needed to disable and enable things based on a checkmark being checked.
 
No, it did not work. Thanks anyway...

What is happening is that it will show the Chronic label, but it shows for all records or it doesn't show up at all.

There has to be a way to hide/unhide a label, using code or something, when running a report.

Any other suggestions?

Wantabie
 
How are ya Wantabie . . . . .

Try this in the [blue]On Format Event[/blue] of the [blue]Detail Section[/blue] ([purple]remove the code in the Open Event first![/purple]):
Code:
[blue]   If Me!Chronic = True Then
      Me!lblChronic.Visible = True
   Else
      Me.lblChronic.Visible = False
   End If[/blue]

The Key: The [blue]On Format Event[/blue] occurs for each record in the [blue]Detail Section[/blue]! . . . [purple]You can do a great many things with this guy![/purple]

Calvin.gif
See Ya! . . . . . .
 
Thanks AceMan1, but the suggestion that Plank provided in thread 703-893155
with,
Code:
 IIF([Boolean Field]='yes', [email address],"")
worked out great. I was using a boolean field to indicate a special record and then using a label to show the indication in the report. With the suggestion, I was able to implement it into the query, that serves as the reports recordsource.

However, I will put your suggestion to use, as I will be try other things with my report(s) in the near/immediate furture.

Thanks again AceMan1, for your suggestion.

Wantabie
 
Wantabie . . . . .

No problem. I just wanted to introduce you to the power of the [blue]On Format Event[/blue] of the [blue]Detail Section[/blue].With it you can format on the fly, record by record.

Shading alternated records, hiding fields, enmuerating, highlighting . . . . .ect.

Note: An [blue]On Format Event[/blue] occurs for each section of the report. But the [blue]Detail Section[/blue] is the only one that occurs for each record. [purple]Very powerful stuff here![/purple]

[blue]You Take Care . . . . . Ya Hear![/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top