PDA

View Full Version : Update data in the selected rows only in the datasheet



kbsudhir
08-20-2009, 04:02 PM
Hi All,


The subform is in datasheet view which is attached to a query.
The subform is displayed whenever I click a button with latest data as per the query.
Now, I want to update only a specified field in the datasheet. One way is update each row one by one. Other is update the selected rows only.

I want to know how to select a bunch of rows in the subform. So that when I click update button in the parent form, only the field in the selected rows should be update. The data which will be updated in the field will be available in a combo box in the parent form.

Please guide.

kbsudhir
08-21-2009, 07:05 AM
Guys, any idea how to go about selecting the rows in the datasheet.

Any guidance is appreciated.

Regards
Sudhir

hansup
08-21-2009, 06:26 PM
I want to know how to select a bunch of rows in the subform. So that when I click update button in the parent form, only the field in the selected rows should be update. The data which will be updated in the field will be available in a combo box in the parent form.You got me curious, Sudhir. I think you can use the SelTop and SelHeight properties of the subform. I selected the fourth row in a subform datasheet, then extended the selection to include two more rows. I used the Immediate Window to find out about those properties:
? Forms!frmMainFoo!frmSubFoo.Form.SelTop
4

? Forms!frmMainFoo!frmSubFoo.Form.SelHeight
3
However, if you click a command button, the focus moves off the datasheet and those properties are no longer useful. Visit these two links to see if you can figure out a method to do what you want:

http://www.mvps.org/access/forms/frm0033.htm

http://groups.google.com/group/microsoft.public.access.formscoding/browse_thread/thread/40a301e5669768b

Let us know how this turns out.

Good luck,
Hans

kbsudhir
08-22-2009, 04:33 AM
Thanks Hans for the guidance. I will check this out & let you know how it worked out for me.

:beerchug:

Regards
Sudhir

kbsudhir
08-23-2009, 07:00 AM
I used the below the code. I selected a bunch of rows in my subform & then click the button to see whether it returns the counts of rows selected.

MsgBox Me.Assignments_subform.Form.SelHeight

But it returned zero. I have no Idea where I went wrong.

hansup
08-23-2009, 07:26 AM
I used the below the code. I selected a bunch of rows in my subform & then click the button to see whether it returns the counts of rows selected. That's what I tried to tell you --- clicking a command button moves the focus away from the rows selection and you can't use the selection properties. Here is a quote from the first link I gave you:

Unfortunately the event that runs this code must either be present behind the form's OnTimer event or a separate custom toolbar. This is due to the fact that the selection is valid only as long as the control focus is on the datasheet. As soon as the focus moves to another control (for example when you click on a command button), the selection is invalidated and the aforementioned properties will not be of any use.

Instead, try to experiment with the keyboard shortcut approach as described in the second link.

Hans