Consulting

Results 1 to 3 of 3

Thread: Print forms with different visible records

  1. #1
    VBAX Mentor OTWarrior's Avatar
    Joined
    Aug 2007
    Location
    England
    Posts
    389
    Location

    Print forms with different visible records

    Hello

    I am creating a form that will display certain objects as visible if they match with the current record.
    For example, if the value is 5, then 5 images will show.

    This work fine in form view, but when I try to print (or print preview), the visible settings only match the first form (so everything shows).

    Is there a way of forcing the print preview to execute code?

    This is the code I need it to call

    Private Sub Form_Current()Dim k As Integer
    
    
    Call img_select
    'turn meter
    Call tm_sel(tm)
    
    
    'power meter
    If [card number] = 19 Then ' dh and mj
        If IsNull([pm]) Then
            Call PM_sel(5, True)
        Else
            Call PM_sel([pm])
        End If
    ElseIf [card number] = 17 Then ' bp
        For k = 0 To 4
            Me.Controls("pm" & k).Visible = True
            Me.Controls("pm" & k & "l").Visible = True
        Next k
        Me.Controls("pm" & 5).Visible = True
        Me.Controls("pm" & 5 & "l").Visible = True
        Me.Controls("pm" & 5 & "l").Caption = "X"
    Else
        Me.Controls("pm" & 5 & "l").Caption = 5
        Call PM_sel(pm)
    End If
    
    
    'health meter
    If [card number] = 24 Then
        Call HM_sel(12)
    Else
        Call HM_sel(hm)
    End If
    
    
    
    
    
    
    Select Case [Type]
        Case "Control": [Detail].BackColor = RGB(222, 235, 247)
        Case "Leader": [Detail].BackColor = RGB(255, 242, 204)
        Case "Power": [Detail].BackColor = RGB(225, 63, 51)
        Case "Special": [Detail].BackColor = RGB(173, 135, 249)
        Case "Special / Control": [Detail].BackColor = vbBlue + vbRed + vbBlue
        Case "Special / Power": [Detail].BackColor = vbBlue + vbRed + vbRed
        Case "Troop": [Detail].BackColor = RGB(226, 240, 217)
    End Select
    
    
    
    
    If IsNull([pa]) Then
        [pa].Visible = False
        [pal].Visible = False
        [pabk].Visible = False
    Else
        [pa].Visible = True
        [pal].Visible = True
        [pabk].Visible = True
    End If
    
    
    If IsNull([la]) Then
        [la].Visible = False
        [lal].Visible = False
        [labk].Visible = False
    Else
        [la].Visible = True
        [lal].Visible = True
        [labk].Visible = True
    End If
    
    
    If IsNull([Notes]) Then
        [Notes].Visible = False
    Else
        [Notes].Visible = True
    End If
    
    
    End Sub
    This calls variations on this code

    Function tm_sel(tm_Val As Integer)Dim i As Integer
    i = 0
    
    
    For i = 0 To 6
        Me.Controls("tm" & i).Visible = False
        Me.Controls("tm" & i & "l").Visible = False
    Next i
    
    
    i = 0
    For i = 0 To tm_Val
        Me.Controls("tm" & i).Visible = True
        Me.Controls("tm" & i & "l").Visible = True
    Next i
    
    
    [tmMax].Caption = "(When this reaches " & tm_Val & ", Reset to 0 after activation)"
    
    
    End Function
    -Once my PC stopped working, so I kicked it......Then it started working again

  2. #2
    Quote Originally Posted by OTWarrior View Post
    This work fine in form view, but when I try to print (or print preview), the visible settings only match the first form (so everything shows).

    Is there a way of forcing the print preview to execute code?
    You are printing the form? - Then, I think, this is not possible.

    You should create a report for printing. In a report there is a Format-Event for the Detail Section. In that event you can hide/show certain controls based on the data of the current record.
    Learn VBA from the ground up with my VBA Online Courses.

  3. #3
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    It is possible to convert a form to a Report, but the VBA code is different from one to the other.
    AS PhilS says you can program the details section and also program the On Load event of the Report and also the On Format events of things like group Headers etc.

Posting Permissions

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