Others

Automatically Create a Related Document Record in Microsoft Access

Aamir Naveed AkramAamir Naveed Akram Nov 25, 2026 868 views

Question details

Create a related document record after an internship record is added, without duplicating data or creating placeholder documents.

Automatically Create a Related Document Record in Microsoft Access
Product
Microsoft Access
Device & OS
not provided
Scenario
An Access form saves an internship and, when a document is ready, adds a corresponding record to a shared DOCUMENT table.
Observed behavior
The document record should reference the internship and document type through foreign keys, while Access generates its document number automatically.
Before you start

Identify the internship primary key, the matching foreign key in DOCUMENT, and the document-type key. Confirm that NUM_DOC is an AutoNumber field and that a document should be created when the form saves the internship.

Solution 1Recommended

Add the Document Record After the Internship Is Saved

Use the form's After Insert event when the document is ready at the same time as the internship record.

The example assumes numeric fields named InternshipID and DocumentTypeID, a table named DOCUMENT, and a form control named cboDocumentType. Replace these names with those in your database.

If the document is not yet ready, do not create a placeholder. Use a later document-submission action instead.

1
Set up the relationships

In Access, open Database Tools > Relationships. Connect the internship primary key to DOCUMENT.InternshipID and the document-type primary key to DOCUMENT.DocumentTypeID. Enforce referential integrity where appropriate.

2
Open the form event

Open the internship form in Design View. In the Property Sheet, select the form, choose the Event tab, and set After Insert to [Event Procedure]. Click the build button to open the VBA editor.

3
Insert the related document

Add code to the form's AfterInsert procedure. This example skips the insert if no document type is selected: Private Sub Form_AfterInsert() On Error GoTo InsertError If IsNull(Me.cboDocumentType) Then Exit Sub CurrentDb.Execute "INSERT INTO DOCUMENT (InternshipID, DocumentTypeID) VALUES (" & CLng(Me.InternshipID) & ", " & CLng(Me.cboDocumentType) & ")", dbFailOnError Exit Sub InsertError: MsgBox "The internship was saved, but the document record was not created. " & Err.Description End Sub

4
Test the form

Save the form, open it in Form View, select a document type, and add an internship. Check the DOCUMENT table for a new record with the correct foreign keys and an automatically generated NUM_DOC.

Add the Document Record After the Internship Is Saved
Handle skipped or failed inserts: The internship can be saved even if the document insert is skipped or fails. Provide a later document-submission action and check for an existing document before retrying if duplicates are not allowed.
Free Microsoft Office alternative

Work With Internship Documents in WPS Office

WPS Office is a free, lightweight alternative for editing and sharing office documents, with a familiar interface that makes migration easy. It does not replace Microsoft Access or run Access database forms.

Prepare internship documents and reports in a familiar interface.Open and edit Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTX.Use a lightweight office suite with free tools for everyday document work.Move existing office documents into WPS Office without changing your usual file formats.
microsoft office alternative - wps office

Frequently Asked Questions

Why should I omit NUM_DOC from the insert statement?

NUM_DOC is an AutoNumber field, so Access generates its value when the DOCUMENT record is inserted. The INSERT statement only needs the required foreign keys and any other required fields.

What if the document is submitted after the internship ends?

Do not create a placeholder. Use a DOCUMENT entry form or a submission button later, and supply the saved internship's primary key as the document's foreign key.

How should I handle an internship with multiple students?

Use separate internship and student tables with a junction table containing their foreign keys. This represents the many-to-many relationship without duplicating student details in DOCUMENT.

Can the DOCUMENT table also contain books?

Yes. A shared DOCUMENT table can hold different document types. Use a document-type foreign key and define relationships and required fields appropriate to each type.

Does WPS Office run an Access After Insert event?

No. The VBA form event runs in Microsoft Access. WPS Office can be used for related Word, Excel, and PowerPoint documents, but it does not replace Access database forms.