473,511 Members | 15,046 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.rowcount
for count = 0 to i
subform.field.value = calc_value
next

any help will be appreciated

Regards
Nanda
Jul 31 '07 #1
4 9237
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.rowcount
for count = 0 to i
subform.field.value = 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 :

TimesheetDetails.Form.Recordset.MoveFirst
With TimesheetDetails.Form.Recordset
Do While Not .EOF
TimesheetDetails!Date = getdateforweeknum(wknum, TimesheetDetails!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
2266
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...
3
1612
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...
4
34576
by: Kelvin | last post by:
Dear All, Please help. Same as subject !!!
1
22515
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...
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...
1
5377
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...
0
1228
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...
1
3741
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...
1
11344
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...
0
7137
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
7349
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,...
1
7074
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...
0
7506
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
5659
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,...
1
5063
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
4734
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3210
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
445
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...

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.