Create Multiple records in a subform base on two fields

G

Guest

I have a form with a subform and it work great. The only thing is that In
the Main form I have 2 fields. Both fields is for reference. For example 1
say "1234" and the second one say "1236". I want to create a botton that
when I press it, it will create 3 records in the subform and in the Parcel
filed in the subform will create from 1234 to 1236.

Main form
Field 1 Field 2
1234 1236


Sub form
Primary key Parcel #
1 1234
2 1235
3 1236
 
A

Allen Browne

AddNew to the RecordsetClone of the form in the subform control:

Dim lngCount As Long
With Me.[NameOfYourSubformControlHere].Form.RecordsetClone
For lngCount = Me.[Field1] To Me.[Field2]
.AddNew
![Parcel #] = lngCount
.Update
Next
End With
 
G

Guest

I'm not that good in access... Can you show me how and where do I put this
codes?

Allen Browne said:
AddNew to the RecordsetClone of the form in the subform control:

Dim lngCount As Long
With Me.[NameOfYourSubformControlHere].Form.RecordsetClone
For lngCount = Me.[Field1] To Me.[Field2]
.AddNew
![Parcel #] = lngCount
.Update
Next
End With

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Victor Torres said:
I have a form with a subform and it work great. The only thing is that In
the Main form I have 2 fields. Both fields is for reference. For example
1
say "1234" and the second one say "1236". I want to create a botton that
when I press it, it will create 3 records in the subform and in the Parcel
filed in the subform will create from 1234 to 1236.

Main form
Field 1 Field 2
1234 1236


Sub form
Primary key Parcel #
1 1234
2 1235
3 1236
 
A

Allen Browne

1. Set the On Click property of your button to:
[Event Procedure]

2. Click the Build button (...) beside the property.
Access opens the code window.

3. Place the lines betwen the "Private Sub..." and "End Sub".

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Victor Torres said:
I'm not that good in access... Can you show me how and where do I put
this
codes?

Allen Browne said:
AddNew to the RecordsetClone of the form in the subform control:

Dim lngCount As Long
With Me.[NameOfYourSubformControlHere].Form.RecordsetClone
For lngCount = Me.[Field1] To Me.[Field2]
.AddNew
![Parcel #] = lngCount
.Update
Next
End With


Victor Torres said:
I have a form with a subform and it work great. The only thing is that
In
the Main form I have 2 fields. Both fields is for reference. For
example
1
say "1234" and the second one say "1236". I want to create a botton
that
when I press it, it will create 3 records in the subform and in the
Parcel
filed in the subform will create from 1234 to 1236.

Main form
Field 1 Field 2
1234 1236


Sub form
Primary key Parcel #
1 1234
2 1235
3 1236
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top