Create multiple records from one form based on quantity (1 Viewer)

Edy

New member
Local time
Today, 08:57
Joined
Feb 13, 2018
Messages
6
I have a form that fills in information in a table. It currently creates one record at a time.

Is it possible to have the form create multiple duplicate records in the table based on a quantity input? The primary key would, of course, be different for each new record.
 

plog

Banishment Pending
Local time
Today, 10:57
Joined
May 11, 2011
Messages
11,638
Yes, but it seems improper to add completely duplicated records to a database. Can you explain what this system is for and what you hope to accomplish with the duplicated records?

In a nutshell, this would be accomplished with an unbound form (not tied to a table) and some VBA (to run a loop which executes an INSERT statement however many times you need it to).
 

Edy

New member
Local time
Today, 08:57
Joined
Feb 13, 2018
Messages
6
Maybe my concept for this table is incorrect, so I am open to suggestions.

I am making something like an asset tracking database. The table is an inventory of items, each with a unique auto-generated serial number so they can be checked in and out of storage. I am populating that table with a form and currently, I can only enter one item at a time. So if I have 6 of the same item, I have to input the same information into the form 6 times.

I would like to be able to enter the item information once, including a quantity, and have it create records for each item in the table.
 

plog

Banishment Pending
Local time
Today, 10:57
Joined
May 11, 2011
Messages
11,638
That sounds valid. The method I described in my first post would be the way to achieve it.
 

Edy

New member
Local time
Today, 08:57
Joined
Feb 13, 2018
Messages
6
Can you please expand on the explanation? Sorry, I'm an Access/VBA/SQL novice.

The form is unbound to let the INSERT command handle all the data entry?
Is the INSERT command an SQL command or is it built into VBA?

Thanks.
 

plog

Banishment Pending
Local time
Today, 10:57
Joined
May 11, 2011
Messages
11,638
A bound form directly interacts with tables. What you type in gets passed onto the table.
You don't want that. What you type in, you want to add to the table multiple times. To achieve this you use an unbound form (not attached to the table).

So, to get the form to interact with the table you need to write code to do so. SQL is the language of databases--it produces queries that show you data as well as has keywords that interact with data (add/edit/delete). You will need to use the keyword 'INSERT INTO' to add data to a table.

VBA is a general programming language used in Access. It connects the form to the SQL. When a user clicks the 'Add Records' button on your form it is what will run. Part of that code will be the DoCmnd.RunSQL method (https://msdn.microsoft.com/en-us/vba/access-vba/articles/docmd-runsql-method-access). That will send a request off to the database engine to execute your SQL INSERT INTO statement.
 

Users who are viewing this thread

Top Bottom