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

Conditional printing based on a checkbox - need to know how

Status
Not open for further replies.

xicana

Technical User
Dec 11, 2003
100
US
I need to modify an existing invoicing database:

I'd like to select which items of an invoice I would like to show on the actual invoice printout. There's a "Print" checkbox field in each record in the invoice details table. When this field is unchecked, I would like for that line item (entire record) to not print on the invoice report. I figured I could set the visible properties of the different fields in the detail section to False when the checkbox is not checked. I believe it should be in the OnFormat event of the detail section of my report - but I've tried several options and I cant' get it to work.

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If Me!chkPrint = True Then
        Me!Item.Visible = True
    Else
        Me!Item.Visible = False
    End If
    
End Sub
this gives me the following error: "Runtime error '2427': you entered an expression that has no value"

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If Me!chkPrint = -1 Then
        Me!Item.Visible = True
    Else
        Me!Item.Visible = False
    End If
    
End Sub
the above code gives me the same error.

what am I doing wrong?

Sandy
 
I believe I've gotten this to work this is what I put down in my code:

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Dim ctrl As Control

    For Each ctrl In Me.Controls
        If Me!chkPrint = -1 Then
            With ctrl
               .Visible = True
            End With
        Else
            With ctrl
                .Visible = False
            End With
        End If
    Next ctrl
End Sub

the only thing that bugs me is the blank spaces left...I guess it has to do with the blank spaces between my controls...I'll see if I can set some text boxes between them so that they can shrink as well (thus shrinking the space).

***by the way, i first placed that piece of code in the OnPrint event and I was getting some strange results (the item I had unchecked was not printing, but then the item directly below would not print either...

Sandy
 
I just realized that if I uncheck the last item on the list, the header on my report doesn't print....why does that happen?

Sandy
 
What I ended up doing was this on the onprint event of the report header:

Code:
Dim ctrl As Control

    For Each ctrl In Me.Controls
            With ctrl
               .Visible = True
            End With        
    Next ctrl

that assured that no matter what, the header will print. this may be something to deal with if ever we need to limit what prints on the header.


Sandy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top