Incrementing (1 Viewer)

kitty77

Registered User.
Local time
Today, 03:45
Joined
May 27, 2019
Messages
693
How can I create a form that has a button with an input field where I can put in a number.
It would generate that many records incrementing by one for each record?
So, the table would have some number, say 5005 and I would enter 25 and get 25 records plus 1.

Thanks.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 07:45
Joined
Feb 19, 2013
Messages
16,553
why the plus 1? and what is the relevance of 'some number say 5005'

Are you saying if a table has 5005 records and you want to add 25 so it will then have 5030 records? or is it 5031 records?
Or are you saying it has a number of records (say 50) and one of the records has a field with a value of 5005? so you would end up with 75 records? or 76 records?

And what are you populating the new records with? some field with 5006, 5007, etc, just using the autonumber?

After nearly 500 posts you should know by now we are not mind readers and can advise better if we are provided with some example data and the outcome required based on that example data

best I can suggest is in your button click event some code along the lines of

Code:
dim i as integer
for i=1 to me.inputcontrol
   currentdb.execute "INSERT INTO myTable (somefield) VALUES(" & 5005 +i & ")"
next i
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 02:45
Joined
Feb 28, 2001
Messages
27,001
In general, Access works best when it does whatever it is going to do "on the fly" and pre-allocating a bunch of records isn't normally needed. There are, of course, exceptions. Can you give us a hint as to the purpose of pre-allocating records? Note that if your goal is to assure a continuously numbered set of records in a group, you might have a design problem anyway. Of course, you CAN do such a thing. CJ's suggestion is one way to do it. But ... why?
 

kitty77

Registered User.
Local time
Today, 03:45
Joined
May 27, 2019
Messages
693
why the plus 1? and what is the relevance of 'some number say 5005'

Are you saying if a table has 5005 records and you want to add 25 so it will then have 5030 records? or is it 5031 records?
Or are you saying it has a number of records (say 50) and one of the records has a field with a value of 5005? so you would end up with 75 records? or 76 records?

And what are you populating the new records with? some field with 5006, 5007, etc, just using the autonumber?

After nearly 500 posts you should know by now we are not mind readers and can advise better if we are provided with some example data and the outcome required based on that example data

best I can suggest is in your button click event some code along the lines of

Code:
dim i as integer
for i=1 to me.inputcontrol
   currentdb.execute "INSERT INTO myTable (somefield) VALUES(" & 5005 +i & ")"
next i
I'll figure it out CJ...
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:45
Joined
Feb 19, 2002
Messages
42,981
I guess since your business need is a secret we'll just have to guess. I'll assume that you know what you are doing and therefore are not generating "empty" records without good cause. Here's a sample of how it is done. Create a table which some people call a "tally" table. It needs as many rows as your maximum duplication requirements. If you never need to generate more than 25 records than 25 rows numbered 1-25 will suffice. If you need 100, then 100 rows numbered 1-100.

The sample uses a Cartesian product to duplicate the copied row by joining to the tally table using a non-equi join.
 

Attachments

  • TallyTableSample20210217.zip
    2.9 MB · Views: 160

theDBguy

I’m here to help
Staff member
Local time
Today, 00:45
Joined
Oct 29, 2018
Messages
21,358
And in case you want to see another example, take a look at these articles.


 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:45
Joined
Oct 29, 2018
Messages
21,358
@theDBguy did you not like my example? It was right on point.
Sorry, I didn't open your attachment. I just assumed it was a demo showing the functionality to the OP. So, I just thought I would add a reference explaining how that functionality works and the steps to recreate it.

When I get in front of a computer, I'll take a look and see if I made a mistake. No offense was intended.

Sent from phone...
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:45
Joined
Feb 19, 2002
Messages
42,981
No problem. Sometimes too many options can be confusing.
 

Users who are viewing this thread

Top Bottom