473,397 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Mailing Labels

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

Dec 7 '05 #1
1 2472
I see nothing in the code that would delete the first surname in the
listing. However, there are a couple of things you may want to look at.

1) Surnames may have apostrophes in the (i.e. O'Hare). Your code will fail
if that is the case because you are using apostrophes as the delimiter. Try
the following adjustment:

strSurname = strSurname & ",""" & Me.lstSurname.ItemData(varItem) _
& """"

This changed each apostrophe to 2 double quotes. Since double quotes are
string delimiters also, you have to double them up to tell VBA that you
really mean for the double quote to be part of the string instead of a
delimiter. You may actually have to concatenate them in as double quotes if
the IN statement fails with the above. This would be for the same reason as
mentioned above for the apostrophes. The doubled up double quotes will put a
single double quote in the string as part of the string, this may cause a
problem with the IN statement. If so, they will need to be placed into the
string as doubled up double quotes. This would require replacing each
apostrophe with 4 double quotes instead of 2.

2) What if two people have the same surname? It would be better to use a
PersonID field or some other field that uniquely identifies the person.
--
Wayne Morgan
MS Access MVP
"Malcolm Webb" <mf********@yahoo.co.uk> wrote in message
news:me************************@mfwebb.compulink.c o.uk...
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

Dec 7 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mark V. | last post by:
Here's what I have and I'm stumped. I have a table that has several thousand names and addresses. I only want to send to one address in a household. So what I would like to do is create a new...
0
by: Nothing | last post by:
Is there a module that I can add to Access 2000 or above that I can add so that the end user can do mailing labels on teh fly. I know Access can do mailing labels form teh wizard, but I wanted to...
2
by: Bobbie | last post by:
I am trying to make mailing labels. The zip/postal codes are 9 digits (ex: 40601-0223) I ran a query and put in the input mask 00000/-9999;;_ and it works but when I make the mailing labels and...
3
by: Grim Reaper | last post by:
I print mailing labels out of Access 2000 databases about 3 to 4 times a week. I have been having problems with one thing since I have been printing mailing labels. I print mailing labels by...
3
by: Grim Reaper | last post by:
I know this is probably an easy question, but I could not find/figure it out. Basically, I am printing mailing labels with a "Sorting/Grouping" section that groups the label types together....
2
by: dougjrs | last post by:
I have a table that has a list of people that I would like to do a mailing to. The table has the fields First Name, Last Name, House number, Street name, City, State, ZipCode. What I would like...
2
by: Mikey | last post by:
Sample VB .NET source code to create mailing labels or customized letters using MS Word MailMerge This VB .NET source code will start MS Word and call methods and set properties in MS Word to...
1
by: Ravimama | last post by:
Hi Guys, I have to generate mailing labels for selected addresses using crystal reports. I am loading all the names of the vendors in a checked list box. the user will select a few of the...
7
by: Dave | last post by:
Hi all I have a student database where I would like to be able to print just one mailing label, for the student whose record I am currently accessing on the form. I want to be able to click on...
4
by: Dr Al | last post by:
I have a project which requires the batch import of customer contact information, print mailing labels for those customers who have their date of first letter field in the database set to null, and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.