472,794 Members | 2,118 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,794 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 9755
"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...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?

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.