How to Add Multiple Serial Numbers to Access Tables using VBA or Append Queries
Question details
The user needs to process and insert a pasted list of serial numbers into Access tables with validation, duplicate checks, and calculated expiration dates with a single button click.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Adding a batch of serial numbers to a database table from either plain text input or a linked table, while applying business rules like calculating dates and preventing duplicates.
- Observed behavior
- The user wants to streamline the data entry process into a one-click action that automatically loops through the list, validates each item, and appends the required transaction records.
Before running VBA scripts or append queries, ensure you have verified the target tables have the correct data types for serial numbers and expiration dates.
Use VBA to Process Plain Text Serial Numbers
Ideal for scenarios where users paste a list of plain text serial numbers (one per line) directly into a form.
By utilizing VBA, you can easily parse a block of text, evaluate each serial number, calculate relevant dates, and append records to your Access tables.
The Split function allows you to break the pasted text into an array based on line breaks, making it simple to loop through.
Create an unbound text box on your Access form to receive the pasted list of serial numbers and a command button to trigger the process.
In your button's OnClick VBA event, use the Split function (e.g., items = Split(listText, vbCrLf)) to convert the delimited list into an array.
Use a For loop (For x = LBound(items) To UBound(items)) to iterate through each serial number in the array.
Within the loop, check if the serial number string length is valid, calculate the expiration date using DateAdd, and use DCount to check the database for duplicates.
Execute an INSERT INTO SQL statement via CurrentDb.Execute to append the validated serial number and transaction records to the target tables.

Use an Append Query for Data in Linked Tables
Use this method if the serial numbers are already stored in a linked table or an imported Excel spreadsheet.
Looking for a Lightweight Alternative for Your Daily Office Tasks?
While WPS Office does not include a database management tool like Microsoft Access, it offers excellent free alternatives for Word, Excel, and PowerPoint. If you process lists of serial numbers in spreadsheets before importing them to databases, WPS Spreadsheet provides powerful data validation and batch processing features.
- 1. Download WPS Office: Visit the official WPS website and download the installation package for your operating system.
- 2. Install the application: Run the installer and follow the on-screen instructions to complete the setup process.
- 3. Start processing data: Open WPS Spreadsheet to clean, organize, and format your serial number lists before appending them to your database.

Frequently Asked Questions
How can I prevent duplicate serial numbers when importing?
When using VBA, you can use the DCount function to check if the serial number already exists in your table before executing the insert statement. In an append query, ensure the target field is set as a Primary Key or has a Unique Index, which will automatically reject duplicate entries.
What is the best way to handle carriage returns in a pasted list?
Before splitting your string in VBA, you can use the Replace function to standardize line breaks, or simply split directly using vbCrLf (Carriage Return + Line Feed) as the delimiter for the Split function.
Can I calculate expiration dates directly in an Access Append Query?
Yes, you can use built-in functions like DateAdd directly in the SELECT clause of your INSERT INTO statement to calculate expiration dates dynamically based on the current date or another field in the linked table.




