How do you use labels in access?

Most of the reports that you will create in Microsoft Access will be used for common data printing requirements.

However there are times when entirely different kinds of printouts are required, such as when you need to create mailing labels.

Mailing labels are created in Microsoft Access by using a report. The basic label can be created by starting with a blank form, or you can use the label wizard. The Wizard is much easier to use and can save you a great deal of time.

Usually, in a large enough company, labels will be created for mailing purposes; addressing packages or envelopes. However, it is just as easy to create product labels, name tags or any other type of label. Rather than having to create the report from scratch, or use the standard Access Report Wizard, you will find that the Label Wizard will save a lot of time and will create exactly the kind of result that you need to print labels.

How to Create Mailing Labels

We can create a report, to print mailing labels by using the Mailing Label Report Wizard:

  1. From the database window, select the report objects and choose New
  2. Choose Label Wizard from the new report list
  3. Select a table or query to base the label data on and click OK

    How do you use labels in access?

    The New Report dialog box, choosing the Label Wizard and source data for the report

  4. Choose the type of mailing labels that are to be used and click OK

    How do you use labels in access?

    Label Wizard dialog, allowing you to choose the size of label you will be using

  5. Select the text style that you will use for the label and click Next
  6. Arrange the fields in the Prototype Label box to create the label layout. You can double-click fields to move it to the label box. Press spacebar, add required punctuation, and press Enter as necessary to create your layout. Click Next

    How do you use labels in access?

    Setting up the layout of the labels in the Report Wizard

  7. Select a sort order that you would like to sort the labels by and click Next
  8. Enter a name for your mailing label report and click Finish.
  9. Review the completed report:

    How do you use labels in access?

    The completed report, displaying the label setup

We can change the record source of the report, if for example, the report design suits a different table or query. For instance, if we have a table that holds Customer Names and Addresses and another table that holds similar Supplier information.

An efficient way of producing mailing labels in Microsoft Access, for both sets of data would be to change the record source in the reports properties dialog box.

This MSAccess tutorial explains how to add an independent label on a form without it being attached to a text box in Access 2007 (with screenshots and step-by-step instructions).

See solution in other versions of Access:

  • Access 2003

Question: In Microsoft Access 2007, I want to add a Label on a form without it being attached to a Text Box. How can I do this?

Answer:You've probably seen labels get created on a form whenever you create a Text Box, Combo Box, etc. But you can also create an independent label that is not attached to any other object.

To do this, open your form in Design View. Select the Design tab in the toolbar at the top of the screen. Then click on the Label button in the Controls group.

Then click on the form where you'd lke the label appear and enter the text that you'd like to display in the label.

It's easy to print a single label for one or more records, but when you need to print multiple labels for a single record, you'll need VBA.

How do you use labels in access?

Printing labels is simple if you need only one label for each record in a table or query; a wizard does all the work. But if you need to print more than one label for a single record or multiple records, the wizard is inadequate. For this type of printing task, you’ll need a few additional objects and some Visual Basic for Applications (VBA) code. In this article, I’ll show you how to print one or more labels for a single record. Next month, I’ll show you how to print one or more labels for one or more records.

I’m using Access 2016 on a Windows 10 64-bit system but the objects and code will run in earlier versions through 2003. For your convenience, you can download the example .accdb or .mdb file. This database isn’t appropriate for Access Web Apps or Access Web Services. This article assumes you know how to create a table and use wizards to create forms and reports.

In a nutshell

We’ll start with the table that stores the data you’ll be using in the label report. In this case, we’re using the Customers table from Northwind. (You can use any table you like.) You’ll base a simple form on this table so you can choose the record and specify the number of labels you need. For instance, using the form, you could print five labels for the customer Around the Horn or 15 labels for the customer Familia Arquibaldo.

You’ll make a copy of the table that stores the label information to create a temporary table and base a label report on it. The report doesn’t need all the records from the original table; it needs only the records you want to print. Finally, you’ll need a VBA procedure that runs the show.

More about Software

  • Get Microsoft Office Pro and lifetime access to 5 top apps for $59.99
  • How to return first and last times from timestamps in Microsoft Excel
  • Checklist: Microsoft 365 app and services deployments on Macs
  • Google Workspace vs. Microsoft 365: A side-by-side analysis

Create the temporary table

The temporary table is based on Customers (from Northwind). It should share the common fields necessary for the labels, but not the data. The VBA code we’ll add later will add the records used in the label run. Create the temporary table manually or copy the Customers table as follows:

  1. Right-click Customers in the Navigation Pane and choose Copy.
  2. Right-click in the Navigation Pane and choose Paste.
  3. Enter the name Temporary Customers.
  4. Select the Structure Only option (Figure A).
  5. Click OK.

Figure A

How do you use labels in access?
Create a temporary table based on the table that contains the label data.

If you copied the Customers table, open the copy in Design view and delete the primary key. In addition, make sure none of the fields is required and none has an index. The code will duplicate records, and these table properties will generate errors. Don’t worry if the temporary table contains fields you don’t need for the label report. You can delete them if you like, but they’re harmless.

Create the label report

Next, use the Labels report wizard to generate a report on the temporary table, Temporary Customers. Add the following fields: CustomerID, CompanyName, Address, City, Region, PostalCode, and Country. Name the report Customer Label Report (Figure B). In Access 2016, the wizard is in the Reports group on the Create tab. In Access 2003, use the Report Wizard.

Figure B

How do you use labels in access?
Base a label report on the temporary table.

Create the form

Use the Form Wizard to create a simple form based on the Customers table (not the temporary table). The form will display all the records in the Customers table so you can choose. Remove unnecessary fields or not-the code will reference only those fields you want to include in the label report. To customize the form to fit the task, add a text box, a command button, and some code as follows:

  1. Open the form in Design view.
  2. Add a text box control to the Form Header section and name it txtNumberofLabels.
  3. Enter the caption text Number of Labels.
  4. Add a command button; name it cmdPrintLabels and enter a caption of Print Multiple Labels.
  5. With the button selected, click the Event tab in the Property sheet.
  6. Choose [Event Procedure] from the On Click’s dropdown list (Figure C) and click the Builder button to open the form’s module.
  7. Enter the code in Listing A. Don’t copy and paste from the web page. Copy it from the downloadable database file or import the .cls module, also included in the download. If you’re working with your own data, be sure to update the field and table names, accordingly.

Figure C

How do you use labels in access?
Enter a sub procedure for the button’s Click event.

Listing A

Private Sub cmdPrintMultipleLabels_Click()

'Print multiple labels for current record.

Dim i As Integer

Dim rst As ADODB.Recordset

Set rst = New ADODB.Recordset

'Delete previous label data.

DoCmd.SetWarnings False

DoCmd.RunSQL "DELETE FROM [Temporary Customers]"

DoCmd.SetWarnings True

On Error GoTo errHandler

'Catch blank control.

'If set to 0, label report is blank but runs.

If IsNull(Me!txtNumberOfLabels) Then

MsgBox "Please indicate the number of labels you want to print", _

vbOKOnly, "Error"

DoCmd.GoToControl "txtNumberOfLabels"

Exit Sub

End If

rst.Open "[Temporary Customers]", CurrentProject.Connection, adOpenDynamic, _ adLockPessimistic

'Adds duplicate records for selected company using input value.

For i = 1 To Me!txtNumberOfLabels.Value

With rst

.AddNew

!CustomerID = Me.CustomerID

!CompanyName = Me.CompanyName

!Address = Me.Address

!City = Me.City

!Region = Me.Region

!PostalCode = Me.PostalCode

!Country = Me.Country

.Update

End With

Next i

'Opens report.

DoCmd.OpenReport "Customer Label Report", acViewPreview

rst.Close

Set rst = Nothing

Exit Sub

'Error handling routine.

errHandler:

MsgBox Err.Number & ": " & Err.Description, vbOKOnly, "Error"

DoCmd.SetWarnings True

rst.Close

Set rst = Nothing

End Sub

Run the label report

Return to the database and open the form in Form view so we can use it to generate a custom label report. Earlier, I told you we’d use the built-in filter to select a company. If you like, you can automate this process, but to simplify the example, do the following:

  1. In the Sort & Filter group, choose Filter By Form (Figure D) from the Advanced dropdown.
  2. From the CustomerID dropdown, choose a customer such as BERGS (Figure E). Don’t worry if the CustomerID control displays a value other than the one shown; the feature remembers the last filter.
  3. Click Toggle Filter in the Sort & Filter group and Access populates the form with the selected customer’s data.
  4. Enter the number of labels you want to print, say 5, in the Number Of Labels text box (Figure F).
  5. Click the Print Multiple Labels button to generate the label report shown in Figure G.

Figure D

How do you use labels in access?
Use the Filter By Form option to choose a customer.

Figure E

How do you use labels in access?
Choose a customer.

Figure F

How do you use labels in access?
Enter the number of labels you want to print.

Figure G

How do you use labels in access?
The label report prints five labels for Berglunds snabbköp.

How the code works

Fortunately, the code that runs the show is simple. First, a SQL DELETE statement deletes any existing records from the temporary table (from a previous session). If you omit this statement, you can build a custom report using more than one customer–but at some point, you’d have to clear the table for the next printing task.

The If statement checks the txtNumberofLabels text box for a value. If the control is blank, the code displays a warning message, selects the control, and quits. If the control contains 0, the code displays a blank report. This behavior is something you might want to omit by adding a second If statement or an OR statement to the existing If’s condition.

After opening a Recordset object based on the Temporary Customers table, the For loop uses the value in txtNumberofLabels to add a record for each label. For example, if you enter the value 5, the For loop adds five records.

At this point, the Temporary Customers table contains a record for each label. Opening the report generates the appropriate label report. The error-handling routine is generic; you might want to customize it a bit more to fit your needs.

You can add this simple technique for printing one or more labels for a single record to almost any database. Next month, we’ll tackle printing one or more labels for more than one record.

Send me your question about Office

I answer readers’ questions when I can, but there’s no guarantee. When contacting me, be as specific as possible. For example, “Please troubleshoot my workbook and fix what’s wrong” probably won’t get a response, but “Can you tell me why this formula isn’t returning the expected results?” might. Please mention the app and version that you’re using. Don’t send files unless requested; initial requests for help that arrive with attached files will be deleted unread. I’m not reimbursed by TechRepublic for my time or expertise when helping readers, nor do I ask for a fee from readers I help. You can contact me at [email protected].