Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

duplicating entries on a form 1

Status
Not open for further replies.

montyb

Technical User
Sep 8, 2000
26
0
0
US
I am building a form to enter data on railcars. If I have to enter data on 100 cars, it gets tedious. What I want to be able to do is enter the data once, and have it copy "x" number of times to the table.

In addition, each entry needs to have a unique identifier which will be entered as well. It would be great if I could enter a range of values for this field, and have the rest of the data replicate. Does anyone have a solution?

Thanks in advance. [sig][/sig]
 
Sounds like you might be adding cars into inventory. Each of the cars have general information that is the same, and you want the easy way out!

You could create a form that allows you to enter all the info that will be repeated. A field to enter the number of new entries to make in the car table. And a button to start the process. Am I on the right track? (pun)

John [sig]<p>John A. Gilman<br><a href=mailto:gms@uslink.net>gms@uslink.net</a><br>[/sig]
 
Yes sir, that is exactly what I am looking to do! On a form, enter all the data that will be duplicated as well as have a field that takes a range of car numbers (car #'s 200-215, 360-363, 401, 500-599, etc..). Then a button that will populate a table with the listed car numbers and the duplicated data. [sig][/sig]
 
Just to make sure we are understanding each other regarding the range of numbers. Lets say you are entering some new cars, and the starting car number is NOT generated by the computer, you could enter the starting number into a field called StartNumber and then enter the ending number into a field called EndNumber. Then the code could just start creating new records using the info from the form starting with the start number, increment the number + 1 for each record until the ending number is reached.

If this is what you want to do just let me know, or post more detail regarding the process.

John [sig]<p>John A. Gilman<br><a href=mailto:gms@uslink.net>gms@uslink.net</a><br>[/sig]
 
That is correct. I would be great if I could enter multiple ranges all at once (not all of the cars will be in a consecutive range, see previous reply), however that may be out of my scope. The numbers are not generated by the computer, however there is an autonumber in the table for new entries. I don't suppose that will affect the data entry. What do you suggest? [sig][/sig]
 
I would work with one set of new entries at a time. Enter the numbers like the make belive section above and wait until the code finishes with that batch.

You will need to create an unbound form with all the fields for the user to fill in, including the startNumber and endNumber then the following code will be called from a button click event.

Private Sub cmdAddNewCars_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim newNumber As Integer
newNumber = Me.startNumber
Set db = CurrentDb()
Set rs = db.OpenRecordset(&quot;Your Table Name Here&quot;)
With rs
Do While newNumber <= Val(Me.endNumber)
.AddNew
!Your_Car_Number = newNumber
'add your other fields here
.Update
newNumber = newNumber + 1
Loop
End With

End Sub
[sig]<p>John A. Gilman<br><a href=mailto:gms@uslink.net>gms@uslink.net</a><br>[/sig]
 
John, first off, thanks for the help. I have a couple of questions regarding the above code. While I have done some work in VB, I still have a long ways to go, eitherhoo...

First, when I type in...

Dim db As DAO.Database

DAO does not show up in the drop box as an option. I can choose AccessObject, ACDataObjectType or DataAccessPage (amoung a number of different options). FYI I am working in Access2000. What do I need to do? Do I need to substitute one of the above options?

Does &quot;!Your_Car_Number&quot; represent the car# field in the table? And if so, would the code be written as such

Table!tblName.fieldName = newNumber etc..

Do I need to write any code before &quot;.AddNew&quot; or &quot;.Update&quot;?

Sorry to hassle you with all these questions. I really do appreciate the help. This is an important project I'm on and unfortunately I have no one in the office to reference. Thanks again.
[sig][/sig]
 
You need to set a reference to the DAO Code library. when you are in a code window click tools, references, then find the following library - Talk Microsoft DAO 3.5 Object Library
[sig]<p>John A. Gilman<br><a href=mailto:gms@uslink.net>gms@uslink.net</a><br>[/sig]
 
Ignore the &quot;Talk&quot; in the last posting. :) dont know where it came from ;-)
[sig]<p>John A. Gilman<br><a href=mailto:gms@uslink.net>gms@uslink.net</a><br>[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top