Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 26th, 2007, 04:46 PM
Friend of Wrox
 
Join Date: Jan 2007
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to scandalous Send a message via MSN to scandalous
Default automatically create new records

I am trying to generate new records based on the user filling out a field [Units]

What I want to happen is that it will automatically create the number of records entered into the [Units]field.

Does anyone know what this is called so I can look it up?

 
Old February 27th, 2007, 08:39 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

You need to give more information. What does the database look like before the transaction, what data is entered, and what do you want the database to look like after the transaction.



mmcdonal
 
Old February 27th, 2007, 09:34 AM
Friend of Wrox
 
Join Date: Jan 2007
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to scandalous Send a message via MSN to scandalous
Default

THis is basically what I want to happen.
Scenario:

A salesperson will create a quote that includes the customer information, [#ofUnits] and the [quote#]. [tblQuote]

When they enter the [#ofUnits] on this form and click a button [cmdcreateJobs] it opens a template which asks for the vehicle information.

There is another button [cmdaddparts] where the salesperson will choose the parts and packages that will be used to describe all the units. I will call this the template for all vehicles.

ie #units = 5000
all vehicles are Chevrolet Tohoes 2007 and receive package 1

when they click another button [cmdCreatejobs] the PK and job#'s are created and the template ([quotenumber] followed by sequencial numbering Q-RABA-2/29/07(1)-1 (first unit), Q-RABA-2/29/07(1)-2 (Second Unit) etc on through 5000.)

Basically I am trying to avoid the salesperson from entering the same thing 5000 times.

Unfortunately, I need individual records for this because each unit is billed rather than the group of vehicles.

Do you need any other information. I looked into it and I think I need to do a For...NextLoop. What I do not know is what one looks like.




 
Old February 27th, 2007, 03:08 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I think you already have the code for this to open a connection and recordset. So open those outside the loop. Then in the loop, put your code to create a single record. Then do this:

Dim i, iNoOfUnits As Integer

Take variables
iNoOfUnits = 5000

Create Connection
Create Recordset

set counter to 0
i = 0
'Since i = 0, then you can loop until i = 5000, which will loop from 0 - 4999.

Do Until i = iNoOfUnits
   sUnit = "Q-RABA-2/29/07(1)-" & i
   rs.AddNew
   rs("Field1") = sUnit
   ...
   rs.Update
   i = i + 1
Loop

rs.Close
cn.Close

Regardless of whether you use a For Next, or Do Until Loop, ALWAYS increment the counter, otherwise you will create a million records all with the same values until you just have to dump the database. The increment is the i = i + 1.

Did that help?


mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
create one string from various records paul20091968 Access VBA 1 January 4th, 2007 04:18 PM
Create Related Records twsinc VB How-To 2 October 31st, 2006 06:51 PM
Automatically create tables Machiaveli280278 Access VBA 3 September 26th, 2006 04:20 PM
Create Table's fields from another's Records Jinan BOOK: Beginning Access VBA 0 August 30th, 2004 10:18 PM
I can't create array more than 500000 records. tumarha Pro VB Databases 2 March 1st, 2004 09:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.