473,426 Members | 3,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,426 software developers and data experts.

Adding multiple records to a subform using VB

I have a subform which represents a 1:N relationship with the main
form. I would like to be able to read values from an external file,
fill the subform with the values read & allow the user to view/edit
the values via the subform.

I thought this would be accomplished using a simple loop; read values,
assign the various fields of the subform & repeat for each row of the
subform. Seems this is not possible, or at least I have been unable
to figure it out!

If you have any suggestions, I would greatly appreciate hearing them.

Thanks!

Wendy Powley
School of Computing
Queen's University
Kingston, ON
Nov 13 '05 #1
6 9828
"Wendy Powley" <we***@cs.queensu.ca> wrote in message
news:85**************************@posting.google.c om...
I have a subform which represents a 1:N relationship with the main
form. I would like to be able to read values from an external file,
fill the subform with the values read & allow the user to view/edit
the values via the subform.

I thought this would be accomplished using a simple loop; read values,
assign the various fields of the subform & repeat for each row of the
subform. Seems this is not possible, or at least I have been unable
to figure it out!

If you have any suggestions, I would greatly appreciate hearing them.

From Access 2000 onwards you can programmatically access the forms'
recordset with code like this: (Make sure you set a reference to the DAO
object library)

Dim rst As DAO.Recordset
Dim i As Long

Set rst = Me.Recordset
For i = 1 To 10
rst.AddNew
rst("Field1").Value = "Value1"
rst("Field2").Value = "Value2"
rst.Update
Next i
Set rst = Nothing

Nov 13 '05 #2
Hi Wendy,

In most cases you can get done what you want without any VBA code.

In a backup copy of your application, click the Autoform icon in the
Database|Forms window and create a new form based on your 1 side table.
Clean it up a bit and then extend the bottom of the form enough to hold your
subform when it's ready. Open the datasource for the form and design your
query.

Back at the Database|Forms window, create a new form in a similar fashion.
Do not put a header or footer on this form unless you have them on your
existing subform. Open the datasource for the (sub)form and design its
query. When you are happy with it, close the subform with an appropriate
name.

Open your main form in design mode and reduce its size so that you can find
your new subform in the Database|Forms window. Drag your new subform onto
your new form to a point near the left side of the form and below all
existing controls. Release the mouse and Access will relate a subform
control on your main form and place your subform within it.

Before changing for Form view, look at the properties for the subform
control. You should see the appropriate field name(s) in Link Master Field
and Link Child Field. If those names are missing you have some
troubleshooting to do in your data sources.

HTH

--
-Larry-
--

"Wendy Powley" <we***@cs.queensu.ca> wrote in message
news:85**************************@posting.google.c om...
I have a subform which represents a 1:N relationship with the main
form. I would like to be able to read values from an external file,
fill the subform with the values read & allow the user to view/edit
the values via the subform.

I thought this would be accomplished using a simple loop; read values,
assign the various fields of the subform & repeat for each row of the
subform. Seems this is not possible, or at least I have been unable
to figure it out!

If you have any suggestions, I would greatly appreciate hearing them.

Thanks!

Wendy Powley
School of Computing
Queen's University
Kingston, ON

Nov 13 '05 #3
"John Winterbottom" <as******@hotmail.com> wrote in message news:<2h************@uni-berlin.de>...
From Access 2000 onwards you can programmatically access the forms'
recordset with code like this: (Make sure you set a reference to the DAO
object library)
<snip code>
Hi John,

Thanks for the response. It looks like exactly what I want. However,
I tried it out (my code looks like the following):
Dim rst As DAO.Recordset
Dim i As Long

Set rst = Me.Form.MySubFormName.Recordset
For i = 1 To 10
rst.AddNew
rst("NameOfTheTextFieldToFill").Value = "Value1"

rst.Update
Next i
Set rst = Nothing


and .. nothing happens. "Value1" does not appear in my text box nor
does the database get updated.

Wendy
Nov 13 '05 #4
"Wendy Powley" <we***@cs.queensu.ca> wrote in message
news:85**************************@posting.google.c om...

Hi John,

Thanks for the response. It looks like exactly what I want. However,
I tried it out (my code looks like the following):
and .. nothing happens. "Value1" does not appear in my text box nor
does the database get updated.


Are you sure the code is running? Set a breakpoint and step through it
verifying that it runs through the loop the requisite number of times. Also
this line:

Set rst = Me.Form.MySubFormName.Recordset

should read

Set rst = Me.MySubFormName.Form.Recordset
Nov 13 '05 #5
Correction .....
Set rst = Me.Form.MySubFormName.Recordset


should read:

Set rst = Me.MySubFormName.Form.Recordset
Wendy
Nov 13 '05 #6
Just a follow-up to my own post in case it helps someone else.

The following works:

rst.AddNew
rst("NAME_OF_FIELD_IN_DB").Value = "somevalue"
....
rst.Update
What I was doing wrong was using the name of the control (the name of
the text box)instead of the name of the field to be updated.

Thanks for the help!

Wendy
Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dee | last post by:
I have a form which contains basics of a customer's order from table . I placed a tab control on this form which is still empty. I'm trying to design a project management database and would like...
6
by: Robin S. | last post by:
**Eric and Salad - thank you both for the polite kick in the butt. I hope I've done a better job of explaining myself below. I am trying to produce a form to add products to a table (new...
6
by: 6thirty | last post by:
Hi, I've created a stocktaking database using Access XP. This is indexed by two fields - part number and shelf location. I am currently inputting all the data via a form. When I have entered a...
0
by: misscrf | last post by:
I am currently working on a database, in 3rd normal form, which is for candidates who apply for a job with the law firm that I workd for. My issue is with good form design. I have a main...
7
by: Ron | last post by:
Hi All, Using Access2000, winXP. Table 1 = tblClients displayed on frmClients via qryClients. 2nd table = tblInvoices shown on frmInvoices via qryInvoices. 2nd table = tblDetails shown on...
0
by: vljones | last post by:
Hoping to find a way of entering new data into a combo box which contains a list of items contained in a table. In addition I want to allocate an ID number to entries that are not currently in...
0
by: Richnep | last post by:
Hi all,. I have a small issue I would like to resolve with VBA. I have a form which it's fields are bound to a table. Within that form is a subform which is a subtable. Tables relationship...
2
by: altesse33 | last post by:
I have a command button on the main form of my database that allows users to add new records. But, even though new records get added to the sub table when I click on the button, those new records...
3
by: ramprat | last post by:
Hi All, I am using Access 2003 and have a continuous form based on a table (table1) as a subform on another form. I simply want to be able to take any records that get added to table1 through the...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.