473,387 Members | 1,512 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,387 software developers and data experts.

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

547 512MB
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, 93 views)
Mar 6 '11 #1
5 1826
ADezii
8,834 Expert 8TB
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, 78 views)
Mar 6 '11 #2
ADezii
8,834 Expert 8TB
@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 512MB
Thank you i will try to get it to work tonight
Mar 7 '11 #4
neelsfer
547 512MB
Great idea. Thx Mr Adezi. Sure it wil work
Mar 7 '11 #5
ADezii
8,834 Expert 8TB
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
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...
1
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...
1
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...
4
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
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...
4
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.