create asubform with "x" number of data entry lines (1 Viewer)

hawg1

Registered User.
Local time
Today, 17:31
Joined
Sep 24, 2006
Messages
51
Hi,

I've have seen an access database in which a field/box ask's for the number of individuals required for an event. The User, through either a list/combo box or direct entry, enters the number. As soon as user tabs out of box, a subform appears with the same number of empty lines ready for input of the pertinent information (name, age, address, etc.). For example, if the user enters '5', a subform would appear with five blank lines ready for the pertinent information to be entered. Once done, User would click on a button to save this info in a table, each line as an individual record. This program was a third party creation so it was considered proprietary and I couldn't see the code.

I wish to duplicate this process but am having a hard time of it. Any suggestions on how to reproduce this would greatly be appreciated.

Thanks
 

WayneRyan

AWF VIP
Local time
Today, 22:31
Joined
Nov 19, 2002
Messages
7,122
Hawg,

On the surface it seems that statically creating 5 records might be more
like the "spreadsheet" approach. But, there are times when you gotta do
what you gotta do.

However, there are a couple of ways to do this:

Code:
DoCmd.RunSQL "Insert Into YourChildTable (ForeignKey, FieldB, ...) " & _
             "Values (ParentID, 'SomeData1', ...)"
DoCmd.RunSQL "Insert Into YourChildTable (ForeignKey, FieldB, ...) " & _
             "Values (ParentID, 'SomeData2', ...)"
DoCmd.RunSQL "Insert Into YourChildTable (ForeignKey, FieldB, ...) " & _
             "Values (ParentID, 'SomeData3', ...)"
DoCmd.RunSQL "Insert Into YourChildTable (ForeignKey, FieldB, ...) " & _
             "Values (ParentID, 'SomeData4', ...)"
DoCmd.RunSQL "Insert Into YourChildTable (ForeignKey, FieldB, ...) " & _
             "Values (ParentID, 'SomeData5', ...)"

Or

Dim rst As DAO.RecordSet
Set rst = CurrentDb.OpenRecordSet("Select * From YourChildTable")

rst.AddNew
rst!ForeignKey
rst!FieldB = "SomeData1"
rst.Update

rst.AddNew
rst!ForeignKey
rst!FieldB = "SomeData12"
rst.Update

rst.AddNew
rst!ForeignKey
rst!FieldB = "SomeData3"
rst.Update

rst.AddNew
rst!ForeignKey
rst!FieldB = "SomeData4"
rst.Update

rst.AddNew
rst!ForeignKey
rst!FieldB = "SomeData5"
rst.Update

Wayne
 

hawg1

Registered User.
Local time
Today, 17:31
Joined
Sep 24, 2006
Messages
51
Hawg,

On the surface it seems that statically creating 5 records might be more
like the "spreadsheet" approach. But, there are times when you gotta do
what you gotta do.

However, there are a couple of ways to do this:

Code:
DoCmd.RunSQL "Insert Into YourChildTable (ForeignKey, FieldB, ...) " & _
             "Values (ParentID, 'SomeData1', ...)"
DoCmd.RunSQL "Insert Into YourChildTable (ForeignKey, FieldB, ...) " & _
             "Values (ParentID, 'SomeData2', ...)"
DoCmd.RunSQL "Insert Into YourChildTable (ForeignKey, FieldB, ...) " & _
             "Values (ParentID, 'SomeData3', ...)"
DoCmd.RunSQL "Insert Into YourChildTable (ForeignKey, FieldB, ...) " & _
             "Values (ParentID, 'SomeData4', ...)"
DoCmd.RunSQL "Insert Into YourChildTable (ForeignKey, FieldB, ...) " & _
             "Values (ParentID, 'SomeData5', ...)"

Or

Dim rst As DAO.RecordSet
Set rst = CurrentDb.OpenRecordSet("Select * From YourChildTable")

rst.AddNew
rst!ForeignKey
rst!FieldB = "SomeData1"
rst.Update

rst.AddNew
rst!ForeignKey
rst!FieldB = "SomeData12"
rst.Update

rst.AddNew
rst!ForeignKey
rst!FieldB = "SomeData3"
rst.Update

rst.AddNew
rst!ForeignKey
rst!FieldB = "SomeData4"
rst.Update

rst.AddNew
rst!ForeignKey
rst!FieldB = "SomeData5"
rst.Update

Wayne


Wayne,

Thanks for the quick reply. I unfortunately have to state that I have no earthly clue as to what you trying to tell me with your code. I have no tables established other than the final table that I wish the 'x' number of records go to (inthe case of the example 5). I am not that knbowledgeable with code, but if you give a description of what you are trying to do, I might understand it a little better.

Hawg1
 

hawg1

Registered User.
Local time
Today, 17:31
Joined
Sep 24, 2006
Messages
51
Wayne,

Thanks for the quick reply. I unfortunately have to state that I have no earthly clue as to what you trying to tell me with your code. I have no tables established other than the final table that I wish the 'x' number of records go to (inthe case of the example 5). I am not that knbowledgeable with code, but if you give a description of what you are trying to do, I might understand it a little better.

Hawg1

I think, due to being up to the wee hours of the morning, I miscommunicated my intent.

I have created a subform that has one row of text boxes for a persons first name, middle initial, and last name. On the main form, I would like the user to enter/select a number that represents how many names he/she has for input. Then, based on that number, the subform is adjusted so that there are that many rows onthe subform. For example, user enters/selects 5 since they have five names to enter. As soon as the user leaves the selection box, the subform appears with five rows of text box's, ready for input of first name. middle initial, and last name.
Once that is entered, the user clicks on a command button that transfers each row into a table as a record. So, using the example above, once command button is clicked, the corresponding table would have 5 records, one for each name entered on a row in the subform.

Any help would be greatly appreciated.
 

Users who are viewing this thread

Top Bottom