No filers, no restrictions.
This is a report which details the number of people in the various parts of a retirement community. Each record of a person contains the "wing" location of the residence and the email address if they have one. Sometimes two people are in the same residence.
Apologies for the non-conformance of the code to te standard style. i grew up in a different coding world.
Code:
Private Sub Report_Open(Cancel As Integer)
Dim LastUnitWing As String
Dim dbs As Database
Dim Rec As Recordset
ResCountCottage = 0
ResCountEast = 0
ResCountWest = 0
ResCountAL = 0
ResCountSH = 0
ResCountHC = 0
ResCount = 0
UnitCountCottage = 0
UnitCountEast = 0
UnitCountWest = 0
UnitCountAL = 0
UnitCountSH = 0
UnitCountHC = 0
UnitCount = 0
CottagePix = 0
EastPix = 0
WestPix = 0
ALPix = 0
SHPix = 0
HCPix = 0
ResPix = 0
CottagePixDec = 0
EastPixDec = 0
WestPixDec = 0
ALPixDec = 0
SHPixDec = 0
HCPixDec = 0
ResPixDec = 0
EmailUnits = 0
EmailRes = 0
LastUnitWing = ""
Dim EmailUnit As Boolean
Dim Test As String
Dim TestInt As Integer
Dim Declined As Boolean
Set dbs = CurrentDb
Set Rec = dbs.OpenRecordset("IL_WingUnit") 'This is how we currently limit to IL units and people
With Rec
.MoveFirst
EmailUnit = False
While Not .EOF
a = !LastCommaFirst
.Edit
!UtilityCheck = True
.Update
If !Unit & !Wing <> LastUnitWing Then ' We won't count the same unit/wing twide
If EmailUnit = True Then EmailUnits = EmailUnits + 1: EmailUnit = False
Select Case !Wing ' This covers all cases but only IL cases are presented on the report.
Case "C": UnitCountCottage = UnitCountCottage + 1
Case "E": UnitCountEast = UnitCountEast + 1
Case "W": UnitCountWest = UnitCountWest + 1
Case "A": UnitCountAL = UnitCountAL + 1
Case "S": UnitCountSH = UnitCountSH + 1
Case "H": UnitCountHC = UnitCountHC + 1
Case Else: MsgBox "error in wing ID unit " & !Unit & " wing ID (" & !Wing & "), may be case case."
End Select
UnitCount = UnitCount + 1
LastUnitWing = !Unit & !Wing
End If
Select Case !Wing
Case "C": ResCountCottage = ResCountCottage + 1
Case "E": ResCountEast = ResCountEast + 1
Case "W": ResCountWest = ResCountWest + 1
Case "A": ResCountAL = ResCountAL + 1
Case "S": ResCountSH = ResCountSH + 1
Case "H": ResCountHC = ResCountHC + 1
Case Else: MsgBox "error in wing ID unit " & !Unit & " wing ID (" & !Wing & "), may be case case."
End Select
Dim State As String
State = ""
If !PD = "Y" Then State = "Declined" Else If Trim(Nz(!PictureLink)) <> "" Then State = "Taken"
Select Case !Wing & State 'We don't use this at the present time 12/21/15
Case "CDeclined": CottagePixDec = CottagePixDec + 1
Case "CTaken": CottagePix = CottagePix + 1
Case "EDeclined": EastPixDec = EastPixDec + 1
Case "ETaken": EastPix = EastPix + 1
Case "WDeclined": WestPixDec = WestPixDec + 1
Case "WTaken": WestPix = WestPix + 1
Case "ADeclined": ALPixDec = ALPixDec + 1
Case "ATaken": ALPix = ALPix + 1
Case "SDeclined": SHPixDec = SHPixDec + 1
Case "STaken": SHPix = SHPix + 1
Case "HDeclined": HCPixDec = HCPixDec + 1
Case "HTaken": HCPix = HCPix + 1
End Select
If !EmailAddress <> "" Then EmailUnit = True: EmailRes = EmailRes + 1
ResCount = ResCount + 1
.MoveNext
Wend
ResPix = CottagePix + EastPix + WestPix + ALPix + SHPix 'We don't use this at the present time 12/21/15
ResPixDec = CottagePixDec + EastPixDec + WestPixDec + ALPixDec + SHPixDec + HCPixDec
If EmailUnit = True Then EmailUnits = EmailUnits + 1
End With
'We don't use this at the present time 12/21/15
If CottagePix = 0 Then CottagePixC = "-" Else CottagePixC = Str(CottagePix)
If EastPix = 0 Then EastPixC = "-" Else EastPixC = Str(EastPix)
If WestPix = 0 Then WestPixC = "-" Else WestPixC = Str(WestPix)
If ALPix = 0 Then ALPixC = "-" Else ALPixC = Str(ALPix)
If SHPix = 0 Then SHPixC = "-" Else SHPixC = Str(SHPix)
If HCPix = 0 Then HCPixC = "-" Else HCPixC = Str(HCPix)
If EmailRes = 0 Then EmailResC = "-" Else EmailResC = Str(EmailRes)
If EmailUnit = 0 Then EmailUnitC = "-" Else EmailUnitC = Str(EmailUnit)
End Sub