I need to produce mailing labels every week for staff, but not always for
the same people. I have found a procedure using a filter form which
allows individual names to be selected from a list box which are then
applied to a report for printing.
I have an Employees Table filtered via a query to only show current staff.
My FilterForm is tied to this query and the list box on the filter form
shows surname and forename. I can choose any number of names I require
then click an ApplyFilter command button and my chosen names appear on the
Label Report. Just waht I want.
BUT -- next time I open the filter form there is a name missing. The top
name is missing and when I check the employees table the surname has been
deleted, although all the other information is there. I can easily put it
back. But next time it is deleted again. And if I don't put the first
surname back the next one is deleted.
Can anyone see anything amiss with the following code which would cause
the top surname in the list to be deleted?
Many thanks.
Malcolm Webb
Private Sub btnApplyFilter_Click()
Dim varItem As Variant
Dim strSurname As String
Dim strFilter As String
' Build criteria string from lstSurname listbox
For Each varItem In Me.lstSurname.ItemsSelected
strSurname = strSurname & ",'" & Me.lstSurname.ItemData(varItem) _
& "'"
Next varItem
If Len(strSurname) = 0 Then
strSurname = "Like '*'"
Else
strSurname = Right(strSurname, Len(strSurname) - 1)
strSurname = "IN(" & strSurname & ")"
End If
' Build filter string
strFilter = "[Surname:] " & strSurname
' Open the mailing label report and apply the filter.
DoCmd.OpenReport "LabelsEmployeeAddress", acViewPreview
With Reports![LabelsEmployeeAddress]
.Filter = strFilter
.FilterOn = True
End With
End Sub
Malcolm Webb