Automatically add records base on a field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I have a 2 fields in one form that have two diferents # and a sub form
linked to that form. I need a button that will add the amount of records
starting with the first # to the last. Example:

Main Form:
Field 1= 1000
Field 2= 2000

Subform:
Record 1, Field 1=1000
Record 2, Field 1=1001
Record 3, Field 1=1002....

Can anyone help me on this one?
 
One way is to loop through the values and use an Append query

here is the OnClick code for your command button on the main
form:

'----------------------

if isnull(me.[field1_controlname]) then
msgbox "Please specify Field 1",,"Cannot continue"
exit sub
end if

if isnull(me.[field2_controlname]) then
msgbox "Please specify Field 2",,"Cannot continue"
exit sub
end if

if me.[field2_controlname] < me.[field2_controlname] then
msgbox "Field 2 must be greater than or equal to Field
1",,"Cannot continue"
exit sub
end if

dim i as long, strSQL as string
for i = me.[field1_controlname] to me.[field2_controlname]
strSQL = "INSERT INTO Tablename (Fieldname) " _
& " SELECT " & i & ";"
currentdb.execute strSQL
next i

me.subform_controlname.requery

'----------------------

Warm Regards,
Crystal
MVP Microsoft Access

remote programming and training
strive4peace2006 at yahoo.com
*
Have an awesome day ;)
 
Back
Top