![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a small form with 4 text boxes viz: FromNumber, ToNumber, Form_Type, Insurance_Company When the user enters the parameters & presses a "Generate" button on my form, I'd like the form to create entries from the "FromNumber" to the "ToNumber". eg. if the user has entered: 18, 29, Renewal, Axa ... the form should create the foll entries: 18, Renewal, Axa 19, Renewal, Axa 20, Renewal, Axa 21, Renewal, Axa .. .. 29, Renewal, Axa The 3 fieldnames are: FormNumber, Form_Type, Insurance_Company Could someone kindly post some code using both methods: a) SQL Update b) a single statement in a for loop Also suggestions as to which method would be preferable to use and why. Rgds, Prakash. |
#3
| |||
| |||
|
|
I have a small form with 4 text boxes viz: FromNumber, ToNumber, Form_Type, Insurance_Company When the user enters the parameters & presses a "Generate" button on my form, I'd like the form to create entries from the "FromNumber" to the "ToNumber". eg. if the user has entered: 18, 29, Renewal, Axa ... the form should create the foll entries: 18, Renewal, Axa 19, Renewal, Axa 20, Renewal, Axa 21, Renewal, Axa .. .. 29, Renewal, Axa The 3 fieldnames are: FormNumber, Form_Type, Insurance_Company Could someone kindly post some code using both methods: a) SQL Update b) a single statement in a for loop Also suggestions as to which method would be preferable to use and why. Rgds, Prakash. |
#4
| |||
| |||
|
|
The simplest way to do this would be to create a counting table: say one field named CountID of type Number, marked as primary key, and then save the table as tblCount. Now enter records from zero to the maximum number of inserts you ever need to do at once. If you wish, use the code at the end of this page to populate the table: * *http://allenbrowne.com/ser-39.html Now create a query using tblCount as the source table. In the Field row, type: * * FormNumber: [Forms].[Form1].[FromNumber] + tblCount.CountID In the Criteria row under this, enter: * * <= [Forms].[Form1].[ToNumber] In the next column, in the Field row, enter: * * [Forms].[Form1].[Form_Type] and in the next column: * * [Forms].[Form1].[Insurance_Company] Now turn it into an Append query (Append on Query menu/ribbon.) Access will ask what table to append to. Map these fields to those in your table. For accuracy, it may help to ensure Access understands the data types of the fields correctly. Click Parameters (on the menu/ribbon), and enter 2 rowsin the dialog: * * [Forms].[Form1].[FromNumber] * * * *Long * * [Forms].[Form1].[ToNumber] * * * * * *Long Then set the Format property of both boxes on your form to General Number, so that only valid numbers are accepted. Finally, make sure you exit those boxes on the form before you run the query, to ensure the values are updated. The alternative approach is to OpenRecordset and loop through them. I don't believe that would be as efficient, but for an example of looping througha recordset see: * *http://allenbrowne.com/func-DAO.html...cordsetExample You'll need to use .Edit and .Update. -- Allen Browne - Microsoft MVP. *Perth, Western Australia Tips for Access users -http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Prakash" <prakashwadhw... (AT) gmail (DOT) com> wrote in message news:353ec710-6d99-4664-a947-b941836f0115 (AT) 32g2000prq (DOT) googlegroups.com... I have a small form with 4 text boxes viz: FromNumber, ToNumber, Form_Type, Insurance_Company When the user enters the parameters & presses a "Generate" button on my form, I'd like the form to create entries from the "FromNumber" to the "ToNumber". eg. if the user has entered: *18, 29, Renewal, Axa ... the form should create the foll entries: 18, Renewal, Axa 19, Renewal, Axa 20, Renewal, Axa 21, Renewal, Axa .. .. 29, Renewal, Axa The 3 fieldnames are: FormNumber, Form_Type, Insurance_Company Could someone kindly post some code using both methods: a) SQL Update b) a single statement in a for loop Also suggestions as to which method would be preferable to use and why. Rgds, Prakash. |
![]() |
| Thread Tools | |
| Display Modes | |
| |