473,586 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Looping through rows in a subform

32 New Member
Hello All,

This is my first question in this forum. I have a superform/subform design. When a value changes in the superform, a function is called which which calculate some values, and change it in every row in the subform. I am not able to figure out how to reach every row in the subform. What i need is

i = subform.rowcoun t
for count = 0 to i
subform.field.v alue = calc_value
next

any help will be appreciated

Regards
Nanda
Jul 31 '07 #1
4 9258
ADezii
8,834 Recognized Expert Expert
Hello All,

This is my first question in this forum. I have a superform/subform design. When a value changes in the superform, a function is called which which calculate some values, and change it in every row in the subform. I am not able to figure out how to reach every row in the subform. What i need is

i = subform.rowcoun t
for count = 0 to i
subform.field.v alue = calc_value
next

any help will be appreciated

Regards
Nanda
  1. What is the Linking Field between the Parent Form and Child Sub-Form?
  2. What is the Data Type of this Field?
  3. What value change in the Main Form will trigger Recalculations in the Sub-Form? What is this Field's Name?
Jul 31 '07 #2
ramaswamynanda
32 New Member
Hi,

Thx for replying. here is the info you requested for

What is the Linking Field between the Parent Form and Child Sub-Form? - It is an autogenerated number called timesheetid. for each master row, there are 1-7 detail rows inthe subform, corresponding to the days of the week. the super form has a field called the week number. when the user enters this the detail form is populated with seven rows, with the first column as weekday name, (mon-sun), second column as the date (for that week, for that day) and then some other columns.
What is the Data Type of this Field? the field in question is the date field
What value change in the Main Form will trigger Recalculations in the Sub-Form? when the week number is changed in the master form, for all rows in the detail form, the date value must change.
What is this Field's Name? date

hope the above was helpful.

thanks
nanda
Jul 31 '07 #3
ADezii
8,834 Recognized Expert Expert
Hi,

Thx for replying. here is the info you requested for

What is the Linking Field between the Parent Form and Child Sub-Form? - It is an autogenerated number called timesheetid. for each master row, there are 1-7 detail rows inthe subform, corresponding to the days of the week. the super form has a field called the week number. when the user enters this the detail form is populated with seven rows, with the first column as weekday name, (mon-sun), second column as the date (for that week, for that day) and then some other columns.
What is the Data Type of this Field? the field in question is the date field
What value change in the Main Form will trigger Recalculations in the Sub-Form? when the week number is changed in the master form, for all rows in the detail form, the date value must change.
What is this Field's Name? date

hope the above was helpful.

thanks
nanda
Here is the basic Code Template. Make the necessary substitutions wherever appropriate. Be advised that you can also accomplish the above via an Update Query and a Sub-Form Requery, but I'll leave that for the SQL Gang. In the AfterUpdate() Event of [txtWeekNumber]:
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database, MyRS As DAO.Recordset, MySQL As String
  2.  
  3. MySQL = "SELECT * FROM tblChildTable WHERE [timesheetid] = " & Me![timesheetid] & ";"
  4.  
  5. If Not IsNull(Me![txtWeekNumber]) Then
  6.   Set MyDB = CurrentDb()
  7.   'Recordset for the Sub-Form
  8.   Set MyRS = MyDB.OpenRecordset(MySQL, dbOpenDynaset)
  9.     With MyRS
  10.       .MoveFirst
  11.       Do While Not .EOF
  12.         .Edit
  13.           MyRS![date] = 'whatever you are updating to. One reason why I went with
  14.                                 'code instead of SQL is that I wasn't sure how each 
  15.                                 'Record would be Updated. I feel this is more flexible.
  16.         .Update
  17.         .MoveNext
  18.       Loop
  19.     End With
  20. End If
  21.  
  22. 'Requery the Sub-Form to see the fruits of your labor
  23. Me![subfChild].Requery
Jul 31 '07 #4
ramaswamynanda
32 New Member
hi,

Thanks for the recordset idea. The following code worked :

TimesheetDetail s.Form.Recordse t.MoveFirst
With TimesheetDetail s.Form.Recordse t
Do While Not .EOF
TimesheetDetail s!Date = getdateforweekn um(wknum, TimesheetDetail s!DayofWeek) ' this is the code that calculates the date
.MoveNext
Loop
End With

Excellent !

Best regards
Nanda
Jul 31 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2269
by: Laura | last post by:
Here's the situation: I'm trying to use an update query to copy data from one row to another. Here is the situation: I have 5 companies that are linked to each other. I need to show all 5 companies on a form. 3 of the companies have common employees. I have a table that looks like this:
3
1619
by: Steven | last post by:
OK.. Here's my situation. I have a subform on a parent form. When the parent form is loaded, the subreport queries data from a table in the DB. The parent form has a couple of text boxes for data entry. A command button on the parent form inserts that data from the text boxes into the database... The subreport is then supposed to requery and...
4
34595
by: Kelvin | last post by:
Dear All, Please help. Same as subject !!!
1
22535
by: Kelvin | last post by:
Hi All, I wrote a program insert new row between rows while the datatable is looping. It display the error message. Exception Details: System.ArgumentException: This row already belongs to this table. System.Data.DataTable.InsertRow(DataRow row, Int32 proposedID, Int32 pos) +319 System.Data.DataRowCollection.Add(DataRow row) +14
0
343
by: Kelvin | last post by:
Hi All, While the existing datatable is looping, I can insert new row into datatable, but I can't insert it between datarows. All new rows will inserted into buttom row. Here is my code. Please advise! for (i=0; i < y ; i++ ) {
1
5381
by: Diva | last post by:
Hi, I have a data grid in my application. It has 20 rows and I have set the page size as 5. I have a Submit button on my form and when I click on Submit, I need to loop through the rows in the datagrid. Using the items collection just gives me the 5 rows that are displayed on the screen. Is there any way of looping through all the rows in...
0
1237
by: Krij | last post by:
Hi! I have a problem with the following code (behind a button on frmOrders): (structure: frmOrders->frmOrderdetails (form with subform)) strPutBack = "INSERT INTO tblAmountItems(ItemID,Amount,MyDate,Returned) " _ & "SELECT ItemID,Amount,MyDate,Returned " _
1
3752
by: lucazz | last post by:
I have a main form (not bound to any data source) with a subform based on a query. The subform shows furniture parts according to the criteria specified on the main form. The purpose of the subform is for user to enter produced quantities. To do this I've added a quan field to the subform that is not bound to any data. The problem is that...
1
11382
by: pdesh3 | last post by:
I have created a form where one text box and two command buttons named Search and Clear are present. Under all these fields I am also including a subform which displays all the values stored in Patient table. When I enter any word in the name text box and click enter then the values in sub form only display the details of the patient whose...
0
7911
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8200
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7954
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8215
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3836
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.