PDA

View Full Version : Print forms with different visible records



OTWarrior
05-10-2018, 06:45 AM
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

PhilS
05-10-2018, 11:06 PM
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.

OBP
05-13-2018, 06:15 AM
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.