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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quick Question

Status
Not open for further replies.
Jun 20, 2003
40
GB
I'm new to VBA and I'm creating a Database in Access 2000. I need to create a number of records automaticly, does anyone have any ideas on how I can do this. The set-up is :-

Two tables, one that will be manually populated with a number range, ie START = 0, FINISH = 99.

The code then needs to create a single record for each number in the range above.

So the end result would be.

Table 1

PORT START FINISH
192 1 3

Table 2

PORT ADDRESS
192 1
192 2
192 3

Any help would be great.

Cheers
 
There's no trigger on VBA, so if you want your code starts immediatly after entering the record in the first table, I think it's easier to enter the first record with code too.

So, the vba code could be

'get the start ans end values
dim start as integer
dim end as integer
start=inputbox("Enter the start number")
end=inputbox("Enter the end number")
Dim port as integer

'enter the record into the first table
dim tbl as DAO.Recordset
set tbl=CurrentDb.openRecordset("Table1")
tbl.AddNew
tbl![start] = start
tbl![end] = end
port = tbl![PORT]
tbl.update

'enter the records into the second table
Dim i as integer
set tbl=CurrentDb.openRecordset("Table2")
For i=start to end
tbl.addNew
tbl![Port] = Port
tbl![Adress] = i
tbl.Update
next i

'that's all, don't forget to close recordset
tbl.close

So, these should be one or two errors, but this is the idea


 
Just as a note - you have used the IDEA thread type for this. Please use the QUESTION thread type if you are going to ask a question

Rgds
Geoff
Si hoc legere scis, nimis eruditionis habes
 
You may have received a quicker response to your question if you had given the subject of your post a more descriptive name e.g. Creating records automatically

The following is an FAQ which gives some useful guidelines about using this site's forums:
FAQ222-2244

Hope this helps!

Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top