Full Version: Determine which datasheet row is selected?
UtterAccess Forums > Microsoft® Access > Access Forms
Hope you'll forgive a "newbie" question.
I have a datasheet embedded as a subform in a form.
I want the user to be able to select one of the rows in the datasheet, and then click a button that opens a dialog. The dialog will let the user make specific edits to the data in the selected row.
Here's what I'm having trouble figuring out. How does the button's code determine which row of the datasheet the user selected?
Thanks in advance.
When you click on a button, the current record is selected. But the button must be on the subform.
Make a suboform as a continuous, (instead of datasheet).
You could just set the recordsource for the form(main form?) where you are editing the record so the primary field = the primary field in your subform. And do a form.requery in the click event or type:
orm.recordsource = "Select * from table where primaryID = " & subfromname.form!PrimaryIDfieldname
Here's a handy reference for referring to subform controls, properties:
Thanks for your replies. I'm not sure I'm asking the question correctly.
I have a main form (in form view) with an embedded subform (datasheet). When the user clicks on a row in the datasheet, it puts a little triangle at the start of the row. I'm assuming that means the row is selected in some way.
After a row is selected, I want the user to be able to push a button (on the main form) that brings up a dialog (modal) form that lets the user edit the data from the selected row of the subform.
Does that make sense?
How do I go about doing this?
In your code where you open the form, after the docmd.openform, set the primary field in the form you are opening = to the primary field in the record that is selected on the subform:
forms!newformname!primaryid = subformname.form!PrimaryIDfieldname
You may need to set the new form timer to run a form.requery a couple seconds after it loads. Since the new form may load before it gets the value from the old form. You can post your DB if you want me to look at it.
To answer the crux of your question...
>> "How does the button's code determine which row of the datasheet the user selected?"
It doesn't have to.
By the very definition of it being the selected row - any reference to data in the subform is retrieved from that row.
Thanks for all the help. I tried assigning the primaryID, as suggested by markv. However, in the new form (the dialog for editing the row data), I get a message saying I "can't assign this object"
More specifically, I get "The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship"
This happens even if the dialog is blank and has no controls whatsoever!!!
Oshould add that I have set the record-source for the dialog to be the same query as for the subform. Is this okay?
Any suggestions? Thanks again.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.