Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2010
    Posts
    186

    Unanswered: Using If to hide labels and textboxes in a subform

    I have a single form s/f of invoice details with a record source that is a query.......it's just for viewing purposes so I locked all the fields. I have 2 labels and 4 textboxes (2 dates, 2 numbers) all set to Visible Yes that I need to toggle on and off based on the value of another field. What this means is that if the invoices is paid, then both PID and PDATE have a value in it, so I thought that I could have VBA check one of those fields and either show me or hide the textboxes/labels accordingly. 3 of these show me unpaid invoice details (which every query record has) Label96, AGE, DUE and 3 of these show me paid invoice details Label97, AGE2, PDATE (that every paid query record has)

    There are 2 fields that can be the determining factor to turn off and on - either the PID (hidden) or the PDATE. If either of these has their value (PID is an autonumber field and PDATE is a date field) that means this is a paid invoice so I want to hide all the unpaid details and their label = Label96, AGE, DUE and show me the paid details and their label = Label97, AGE2, PDATE

    In the m/f I do use an after update event to trigger this s/f visible.
    In s/f the Form_current event gives me procedure error so I've done all my tries with Form_Open

    This code is my most recent attempt. The form is showing Label96 and Due on every record so I'm nut sure what is going wrong that it's not triggering?

    Private Sub Form_Open(Cancel As Integer)
    If Me.PID.Value >= 0 Then
    Me.AGE.Visible = False
    Else
    Me.AGE.Visible = True
    End If
    If Me.PID.Value >= 0 Then
    Me.DUE.Visible = False
    Else
    Me.DUE.Visible = True
    End If
    If Me.PID.Value >= 0 Then
    Me.Label96.Visible = False
    Else
    Me.Label96.Visible = True
    End If
    If Me.PID.Value >= 0 Then
    Me.AGE2.Visible = True
    Else
    Me.AGE.Visible = False
    End If
    If Me.PID.Value >= 0 Then
    Me.PDATE.Visible = True
    Else
    Me.PDATE.Visible = False
    End If
    If Me.PID.Value >= 0 Then
    Me.Label97.Visible = True
    Else
    Me.Label97.Visible = False
    End If


    End Sub

    Can anyone steer me in the right direction to fix and text other things? I'm just not sure what else to try!

    Appreciate your feedback!

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    nope
    wrong event
    the event to place this code is the forms on current event
    on open works only when the form is first opened
    on current occurs every time a new row is displayed

    you may be able to make your code more legible by taking advantage of the fact that an if statement is effevctively a boolean operation so you can assign the value of a comparison to a value or property

    eg
    Me.AGE.Visible = (Me.PID.Value >= 0)

    ..or at least you could
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jun 2010
    Posts
    186
    healdem - Thank You!!!
    it works

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •