Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Simbiose is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Posts
    35

    Updating Records Through Subform Row Selection

    Hello again.
    I've hit another bump on my project, yet again regarding subforms.

    I need to be able to select one or multiple rows/records from a subform (that will be displayed in datasheet view and then do something upon the selected rows/records (insert a new record, update value(s), etc).

    The subform is named as dgvFeedStockArticles and its record source comes from a view named qryArtigosMateriaPrimaAEscolher and within the view's query, I've added an expression that gives a boolean result, named as Escolher.
    This is the subform's design:
    Click image for larger version. 

Name:	_1.png 
Views:	25 
Size:	17.3 KB 
ID:	47882
    The very first control is the checkbox that will have the expression as the Source Control, or it would have, because if I do set the sourcecontrol property to that expression I get an error everytime I try to tick the checkbox:




    • The field is based on an expression and cannot be edited


    So, I tried a workaround, such as leaving the sourcecontrol property empty and then set a default value of -1 (which means the checkbox will be empty on loading the records)

    The problem as it is now is that if I tick the checkbox, just for a single record, it automatically ticks the checkbox for all the other records.

    How do I overcome this, in order to only tick the checkbox for the selected record?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The checkbox would need to be bound to a field in the underlying table. You might consider a listbox instead of a subform, which will let you select multiple records more easily.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Simbiose is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Posts
    35
    Quote Originally Posted by pbaldy View Post
    The checkbox would need to be bound to a field in the underlying table. You might consider a listbox instead of a subform, which will let you select multiple records more easily.
    Hello there Paul,
    As soon as I created this thread, your suggestion was a thought that crossed my mind and it's the approach I decided to go with.
    Although, for the sake of this thread and considering of how limited the control is in terms of formatting, such as column head coloring and column alignment, is there no way of achieving the same with a subform?

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    The checkbox must be bound to allow for individual selection. If you add the boolean yes\no field to the back-end table you will have issues with it in a multiuser environment. The solution is to use a local table holding just two fields: the unique ID of the records in the subform (indexed) and a IsSelected yes\no field. Now join this table to the subforms recordsource on the unique ID and bind the checkbox to the IsSelected.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    Simbiose is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2015
    Posts
    35
    Quote Originally Posted by Gicu View Post
    The checkbox must be bound to allow for individual selection. If you add the boolean yes\no field to the back-end table you will have issues with it in a multiuser environment. The solution is to use a local table holding just two fields: the unique ID of the records in the subform (indexed) and a IsSelected yes\no field. Now join this table to the subforms recordsource on the unique ID and bind the checkbox to the IsSelected.

    Cheers,
    Oh wow, that's actually really clever. I didn't think of that.
    Thanks for the help. I know what to do now

    Marking this thread as solved!

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Glad to help ! Just some further info to help you with the setup: usually in some event prior to opening the main form (in the button used to launch it) I would add code to empty the local table then run an append to populate it with the latest unique IDs.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    keviny04 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Apr 2015
    Posts
    128
    Quote Originally Posted by Gicu View Post
    The checkbox must be bound to allow for individual selection. If you add the boolean yes\no field to the back-end table you will have issues with it in a multiuser environment. The solution is to use a local table holding just two fields: the unique ID of the records in the subform (indexed) and a IsSelected yes\no field. Now join this table to the subforms recordsource on the unique ID and bind the checkbox to the IsSelected.

    Cheers,
    I use this method quite often myself, but I don't add separate tables. I put a Yes/No field (or fields) right in the table itself. Adding a second table could be problematic, as you have to sync the two tables constantly.

    By having a Yes/No field in the table itself, any tables and fields that are joined to that table in a query will also be able to use that Yes/No field. Of course, it's best to put this field in tables that are most likely to be the "many" side of a data set, so that you can apply Yes/No to as many unique records as possible. (Tables that don't have any child tables are always the "many" side.)

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    As Vlad pointed out, having that field in the table itself can be problematic in a multiuser environment. If two people are making selections at the same time, they will each get the other's selections as well as their own.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    keviny04 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Apr 2015
    Posts
    128
    Quote Originally Posted by pbaldy View Post
    As Vlad pointed out, having that field in the table itself can be problematic in a multiuser environment. If two people are making selections at the same time, they will each get the other's selections as well as their own.
    That can be solved by having user-specific Yes/No fields. I even have "purpose-specific" Yes/No fields in my single-user tables too. Add as many Yes/No fields as you need because it only takes up one bit per record. You don't split tables every time you have multiple users, so you certainly don't have to split tables just for Yes/No fields.

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    So if you have 100 users you have 100 yes/no fields in the data table, in addition to the normal data fields? And every time they hire somebody you have to modify the db to add a field? And presumably delete one if somebody leaves?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    keviny04 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Apr 2015
    Posts
    128
    Quote Originally Posted by pbaldy View Post
    So if you have 100 users you have 100 yes/no fields in the data table, in addition to the normal data fields? And every time they hire somebody you have to modify the db to add a field? And presumably delete one if somebody leaves?
    And what if the original table has 1 million records and your 100 users create 100 temporary million-record tables all over the place? You can make your absurdly unlikely hypothetical situation and I can make mine. We need the best solution at hand depending on the situation, and you need to consider all possibilities and know their pros and cons.

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I'll let Vlad answer your hypothetical as I don't use either method, I use a listbox.

    I'm not sure how absurd my hypothetical is, I've heard of many developers supporting that 100 or more users. I support quite a few apps but most don't have any more than 20 users. If your solution works for you, great. I personally don't want to have to be involved every time they hire/fire somebody.

    From another perspective, your solution isn't normalized. It's not much different than having a field for every product sold.

    I know you're sold on your method, and as you say you need to consider the pros and cons to make a decision. I'm pointing out the cons so later visitors can make an informed decision.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    keviny04 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Apr 2015
    Posts
    128
    Quote Originally Posted by pbaldy View Post
    I'll let Vlad answer your hypothetical as I don't use either method, I use a listbox.

    I'm not sure how absurd my hypothetical is, I've heard of many developers supporting that 100 or more users. I support quite a few apps but most don't have any more than 20 users. If your solution works for you, great. I personally don't want to have to be involved every time they hire/fire somebody.

    From another perspective, your solution isn't normalized. It's not much different than having a field for every product sold.

    I know you're sold on your method, and as you say you need to consider the pros and cons to make a decision. I'm pointing out the cons so later visitors can make an informed decision.
    The absurdity was in your suggestion that Yes/No fields need to be removed from the table when a user leaves the company. That's almost a troll-like absurdity. You can ROTATE Yes/No fields: when one user leaves, another user takes his Yes/No fields, problem solved! That was what I meant: you had to make up this absurd scenario to prove a point.

    P.S. Multi-select list boxes are a pain to deal with, from my experience. When multiple selections are made, the list box looks like a ZEBRA, and, depending on the color theme used, you may not be able to tell which items are selected and which are not (screenshot). And the properties are cumbersome to deal with: ItemsSelected(), ItemData(), Selected(), etc. "Value List" and "Table/Query" row sources also have different properties, as do single-select and multi-select list boxes. I use list boxes only if I must.

  14. #14
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    @keviny04 - you seem to like your way and dismiss all the rest; I am not here to debate which method is the best.

    I wouldn't use yours for a million bucks (if we get to use millions so easily ) as it would mean I would have to constantly adjust my interface to add fields to queries, forms, VBA, etc. And the tables won't be "all over the place", just one per front-end that can be re-used for multiple back-end tables.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  15. #15
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Just to throw another method into the mix I have used a disconnected ADO recordset in the past. No additional fields or tables required.

    However my preferred method is to add selected ids to a hidden control on the form as a csv and use conditional formatting or similar to indicate selected rows. Benefit is I have a csv of the selected ids so don’t need to do anything more with the form recordset

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 31
    Last Post: 05-29-2017, 08:21 AM
  2. Replies: 1
    Last Post: 03-02-2016, 08:04 AM
  3. Replies: 1
    Last Post: 06-17-2013, 11:44 AM
  4. Replies: 1
    Last Post: 01-08-2013, 02:55 PM
  5. Replies: 3
    Last Post: 11-04-2012, 09:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums