PC Review


Reply
Thread Tools Rate Thread

Automatically add records base on a field

 
 
=?Utf-8?B?VmljdG9yIFRvcnJlcw==?=
Guest
Posts: n/a
 
      3rd May 2006
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?
 
Reply With Quote
 
 
 
 
strive4peace
Guest
Posts: n/a
 
      4th May 2006
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


Victor Torres wrote:
> 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?

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically populate NEW RECORDS in Subform(for field not Linked babs Microsoft Access 13 14th Sep 2009 01:59 PM
Automatically populate a field (create records) from another table =?Utf-8?B?c2FuZHJhaA==?= Microsoft Access Form Coding 11 15th Aug 2007 10:42 PM
Automatically create records with same primary key field =?Utf-8?B?RGlIbw==?= Microsoft Access 1 2nd Jan 2006 04:36 PM
changing a value in one field base on a vlaue in another field =?Utf-8?B?bmV3YmllRGVzaWduZXI=?= Microsoft Access Queries 1 8th Jun 2005 04:34 PM
Automatically uncheck all records in Check box field. Cam Microsoft Access Form Coding 2 23rd Oct 2003 07:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:00 AM.