Locked lesson.
About this lesson
Add an attachment form control.
Exercise files
Download this lesson’s related exercise files.
12.02 attachment-data-type - Exercise.docx53.7 KB 12.02 attachment-data-type - Exercise solution.docx
69.8 KB TechGurusTicketing29.accdb
1.5 MB TechGurusTicketing29 - Complete.accdb
1.6 MB Invoice.pdf
68.3 KB Trip_Itinerary.pdf
82.5 KB
Quick reference
Data Types: Attachments
Add an attachment form control.
When to use
Add an attachment form control whenever you want to create a link to an external document i.e. a pdf file.
Instructions
In this example, we are going to attach a pdf copy of an invoice to the first ticket.
- Open ‘tblTicket’.
- Add a new field with the following properties:
- Name: Invoice
- Data Type: Attachment
- Description: Invoice attachment showing charges
- Indexed: No
- Switch to Datasheet View.
- Double-click the paperclip icon in the first record.
- Click the Add button.
- Browse to the relevant folder and select ‘Invoice.pdf’.
Add the Attachment Form Control
- Open ‘frmTicketMaintenance’.
- From the Form Design tab, in the Form Controls group, select Attachment.
- Draw a text box on the form.
- Click the label and modify the properties in the Property Sheet:
- Name: InvoiceLabel
- Caption: Invoice
- Click on the attachment form control.
- From the Property Sheet, in the Control Source field, click the drop-down and select ‘Invoice’.
- Switch to Form View and review the changes.
- 00:04 Let's finish off this section by talking about another very important data type and
- 00:08 that is the attachment datatype.
- 00:10 So it might be that you want to attach some kind of file to your records.
- 00:16 For example, maybe I want to attach the invoice which shows the charges for
- 00:20 the ticket.
- 00:21 Well, we can do this using the attachment data type.
- 00:24 So let's close down Ticket Maintenance and let's reopen Trouble Ticket.
- 00:30 Now, I'm going to jump straight into Design View,
- 00:33 because we need to add another field.
- 00:36 So this one is just going to be called, Invoice.
- 00:41 Now, the data type for this is going to be Attachment and let's add a description.
- 00:52 Let's check our Field Properties, and for this one,
- 00:55 we only have to caption and required.
- 00:58 Now, this I'm going to leave on no,
- 01:00 because it might not be that there is always an invoice attached to a ticket.
- 01:05 Maybe the work hasn't been completed yet and so no invoice has been sent.
- 01:10 So this isn't a required field.
- 01:13 So now, if we go back to datasheet view, let's save the table.
- 01:18 Notice that we now have another column for attachments.
- 01:22 Now, I've actually prepared a sample invoice and I've saved it as a PDF file.
- 01:28 And we're going to pretend that that is the invoice for Clark Smith.
- 01:32 So let's attach it to a record, all we need to do is double click
- 01:37 in the attachments column and click the Add button.
- 01:41 I'm going to pick it up from the relevant folder, there it is, invoice.pdf and
- 01:45 you'll find this file available to download in the Course Files folder.
- 01:49 And let's click on Open, and I could add multiple attachments if I wanted to.
- 01:55 I would just carry on clicking at, let's click on OK.
- 01:59 And notice now in brackets, it says one, so
- 02:02 I know that I have one attachment for this particular record.
- 02:07 Now that we've added the attachment,
- 02:09 we need to make sure that we show it on the maintenance form.
- 02:12 So let's close down Trouble Ticket, and reopen Ticket Maintenance.
- 02:18 I'm just going to add the attachment at the top just here in the middle.
- 02:21 So let's go into form design and this time from our controls group,
- 02:26 we're going to add this one just here the attachment control.
- 02:31 Let's select it and we're going to draw in the middle just here.
- 02:36 Now, once again, we need to do a little bit of rejigging about.
- 02:40 Now, this can be a little bit smaller and
- 02:43 I'm going to drag that a little bit closer.
- 02:46 I think that looks pretty good.
- 02:48 Let's go over to the Property Sheet and start renaming our labels.
- 02:52 So this is going to be Invoice Label and
- 02:56 the caption is just going to be Invoice.
- 03:01 So now, that I've done that, I can resize this field, drag it over.
- 03:06 Let's drag that one a bit closer as well.
- 03:09 So now, when we click on this field just here,
- 03:11 which is currently not bound to anything.
- 03:14 So we're going to go over to the Property Sheet,
- 03:17 we're going to change the name to Invoice Attachment and the control source.
- 03:24 If we click the drop down is going to be Invoice, really nice and straightforward.
- 03:29 Let's see what that looks like in form view.
- 03:33 Well, there we go, take a look at what we have.
- 03:35 You can see the PDF sitting at the top there.
- 03:38 Now, I can see that I need to give this a little bit more room,
- 03:42 the icon is actually a square icon as opposed to an oblong or a rectangle.
- 03:46 So let's just adjust this very slightly.
- 03:48 Let's jump back into Design View, I'm going to make this a bit longer and
- 03:54 we can make it a bit shorter as well.
- 03:57 Let's take a look at it again.
- 04:00 There we go, that looks slightly better.
- 04:03 Now, this is the only record that I have an invoice for.
- 04:05 So if I double click on it, it's going to open up the attachments panel and I can
- 04:10 then choose if I want to save it, open it, or I can even remove it from here as well.
- 04:16 If I cycle through my other records, I don't have anything in there.
- 04:19 Because it's only the first record that currently has an invoice attached.
Lesson notes are only available for subscribers.