473,756 Members | 6,098 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you add the same value in mainform, to multiple selected rows in subform

547 Contributor
I have a button on mainform that create current time.In the subform, i already have data in some of the fields.
I would like to highlight these specific rows in the subform (select them with mouse) and then add the value created by button on mainform to these selected rows in the subform at once.
Mainform = racef
Subform = timesf
field in subform = timestart
i currently use this code to add the value created by button on mainform, selectively to 1 row in subform at a time.
Expand|Select|Wrap|Line Numbers
  1. GetLocalTime MyTime
  2. [Forms]![RaceF]![TimeSF]![TimeStart] = Format$(MyTime.wDay, "00") & "/" & Format$(MyTime.wMonth, "00") & "/" & MyTime.wYear & _
  3.                                        " " & Format$(MyTime.wHour, "00") & ":" & Format$(MyTime.wMinute, "00") & ":" & _
  4.                                        Format$(MyTime.wSecond, "00") & "." & Format$(MyTime.wMilliseconds, "000")
see attachment; value created in button must be added ie to racenumbers 1 and 3 and 5 at once if i select them using mouse. pls assist
Attached Files
File Type: zip Millisecondsdb 2003_3.zip (89.1 KB, 94 views)
Mar 6 '11 #1
5 1846
ADezii
8,834 Recognized Expert Expert
I found no easy way to do this, but I could be wrong in this matter. I did, however, arrive at a solution which you may/may not like, but here it goes along with a Demo Attached.
  1. Create a Field named [Select] Yes/No in the TimeT Table. This Field will serve no real purpose other than to indicate which records will receive the Start Time Value generated from the Main Form.
  2. Make sure this Field ([Select]) is included in the Sub-Form, TimeSF.
  3. Select records in the Sub-Form for which you wish to transfer the Start Time.
  4. Click on the Start Button.
  5. Clear all the Check Boxes.
  6. If you like this approach, repeat the process for the Finish Time.
  7. I'll post the Code below, but see the Attached for a more detailed view.
P.S. - Only relevant Code has been posted.
Expand|Select|Wrap|Line Numbers
  1. Private Sub start_Click()
  2. Dim MyDB As DAO.Database
  3. Dim rst As DAO.Recordset
  4. Dim strTimeValue As String
  5.  
  6. GetLocalTime MyTime
  7.  
  8. Set MyDB = CurrentDb
  9. Set rst = MyDB.OpenRecordset("SELECT * FROM [TimeT] WHERE [Select] = True;", dbOpenSnapshot)
  10.  
  11. strTimeValue = Format$(MyTime.wDay, "00") & "/" & Format$(MyTime.wMonth, "00") & "/" & MyTime.wYear & _
  12.                        " " & Format$(MyTime.wHour, "00") & ":" & Format$(MyTime.wMinute, "00") & ":" & _
  13.                        Format$(MyTime.wSecond, "00") & "." & Format$(MyTime.wMilliseconds, "000")
  14.  
  15. If rst.BOF Or rst.EOF Then
  16.   MsgBox "No Records Selected", vbCritical, "No Selections"
  17.     Exit Sub
  18. End If
  19.  
  20. With rst
  21.   Do While Not .EOF
  22.     CurrentDb.Execute "UPDATE [TimeT] Set [TimeStart] = '" & strTimeValue & _
  23.                       "' WHERE [Select] = True", dbFailOnError
  24.       .MoveNext
  25.   Loop
  26. End With
  27.  
  28. CurrentDb.Execute "UPDATE [TimeT] SET [Select] = False;", dbFailOnError
  29.  
  30. rst.Close
  31. Set rst = Nothing
  32. End Sub
Attached Files
File Type: zip Millisecondsdb 2003_4.zip (47.0 KB, 79 views)
Mar 6 '11 #2
ADezii
8,834 Recognized Expert Expert
@neelsfer - Oops, think I made a Logic boo-boo. You may wish to revise the previously posted Code to:
Expand|Select|Wrap|Line Numbers
  1. Private Sub start_Click()
  2. Dim MyDB As DAO.Database
  3. Dim rst As DAO.Recordset
  4. Dim strTimeValue As String
  5.  
  6. GetLocalTime MyTime
  7.  
  8. Set MyDB = CurrentDb
  9. Set rst = MyDB.OpenRecordset("SELECT * FROM [TimeT] WHERE [Select] = True;", dbOpenDynaset)
  10.  
  11. strTimeValue = Format$(MyTime.wDay, "00") & "/" & Format$(MyTime.wMonth, "00") & "/" & MyTime.wYear & _
  12.                        " " & Format$(MyTime.wHour, "00") & ":" & Format$(MyTime.wMinute, "00") & ":" & _
  13.                        Format$(MyTime.wSecond, "00") & "." & Format$(MyTime.wMilliseconds, "000")
  14.  
  15. If rst.BOF Or rst.EOF Then
  16.   MsgBox "No Records Selected", vbCritical, "No Selections"
  17.     Exit Sub
  18. End If
  19.  
  20. With rst
  21.   Do While Not .EOF
  22.      .Edit
  23.        ![TimeStart] = strTimeValue
  24.      .Update
  25.        .MoveNext
  26.   Loop
  27. End With
  28.  
  29. CurrentDb.Execute "UPDATE [TimeT] SET [Select] = False;", dbFailOnError
  30.  
  31. rst.Close
  32. Set rst = Nothing
  33. End Sub
Mar 6 '11 #3
neelsfer
547 Contributor
Thank you i will try to get it to work tonight
Mar 7 '11 #4
neelsfer
547 Contributor
Great idea. Thx Mr Adezi. Sure it wil work
Mar 7 '11 #5
ADezii
8,834 Recognized Expert Expert
Glad it all worked out for you, neelsfer.
Mar 7 '11 #6

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

Similar topics

10
3905
by: SHPsalm139 | last post by:
We have an Access 2K application that uses multiple forms. We currently hardcode the release number in a label on each form but this gets tedious to do each time there's a new release. I thought it would be easy to put the new release number in one spot (a table) and have each form reference that table/release number in a text box that I would add to each form but, apparently, it's not as simple as I expected it to be. Would appreciate...
1
1287
by: Steve | last post by:
I have a datagrid, which I can highlight multiple rows in. How can I find out, programmitcally which rows are highlighted? If I step into the code, and do a Quick Watch on the browser I found this: ((System.Windows.Forms.DataGridRow)(((System.Windows.Forms.DataGrid)(dgWork)).DataGridRows)).selected property, which is true for the rows selected, but I cant get to this from within my code???
1
1923
by: Tim Kelley | last post by:
I have a dataViewgrid in my project in which the user will select multiple rows. The will click a button and my program will perform some operation on the selected records (using the ID column value for each of the selected rows). My question is, how do I loop through the selected rows and reference the ID column in the data grid? I can get the count of selected columns, but I don't know how to reference the data in the rows. Thanks.
4
3145
by: Mike | last post by:
Class A public objX I want to create 2 or more instances of Class A and have the same value for objX in all instances. Instance1 of Class A Instance2 of Class A Instance3 of Class A
21
2070
by: vlsidesign | last post by:
This syntax does not to work nl, nt, ns = 0; The only one that get's initialized is ns. nl and nt because they don't initialize seem to get some junk from memory. I have done these two versions that work: nl = 0; nt = 0; ns = 0; nl = nt = ns = 0;
4
4462
by: Brett Wesoloski | last post by:
I am having a bit of a problem getting the current value of the checkbox list. I have tried using the selected value as I thought that would give me the current value of the check box but it appears to be giving me the first value that is selected all the time. I have also tried to use the selectedItem property but that does the same as I would expect becuase the property says it get the item with the lowest value.
0
9454
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10028
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9868
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8709
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7242
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6533
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5139
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2664
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.