Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Apr 2003
    Location
    Calgary, Alberta
    Posts
    327
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting Records Selected From Form (Access 2000)

    I would like to give the user the ability to select several records in a subform and change a value on each of the selected records by entering a single value OR having the value already in a textbox and just hitting a button. How can I find out what records the users has selected? The subform is currently in datasheet form and contains results from a query, with the criteria specified by the user.

    Thanks




    Thanks

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Getting Records Selected From Form (Access 2000)

    You could use the SelTop and SelHeight properties of the form. In a datasheet/continuous form SelTop is the record number of the first selected record, and SelHeight is the number of selected records.

    But I would prefer to use a multi-select list box for this. In a list box with its MultiSelect property set to Extended, the user can select and deselect records using Click, Shift+Click and Ctrl+Click, exactly the way you can select files in Windows Explorer.
    You can use the ItemsSelected or Selected property of the list box to find out which items have been selected, and use this to create an SQL string that will update the corresponding records.

    If you do a search for multiselect in this forum, you will find many threads dealing with this subject, for example <post#=205119>post 205119</post#>.

    Post back if you want more information or need more help.

  3. #3
    3 Star Lounger
    Join Date
    Apr 2003
    Location
    Calgary, Alberta
    Posts
    327
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting Records Selected From Form (Access 2000)

    HI I am using your example with the list box and it works great. What I don't get though is I am currently trying to message what the value in column 2 is for each selected record on a Double Click. Instead, I am just getting the value in column 2 of the last record selected instead of the value in column 2 for each record selected. I am not sure why this loop witl not display the value in column 2 for each record selected.This is what I have:

    Private Sub listbox_Hostesses_DblClick(Cancel As Integer)
    Dim strList As String
    Dim i As Long
    For i = 0 To listbox_Hostesses.ListCount - 1
    If listbox_Hostesses.Selected(i) = True Then
    MsgBox i & listbox_Hostesses.Column(2)
    End If
    Next i

    Thanks for your help
    End Sub

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Getting Records Selected From Form (Access 2000)

    You must also specify the row number:<pre>MsgBox i & ": " & listbox_Hostesses.Column(2, i)</pre>

    Otherwise, you will get a value from the same row each time.

  5. #5
    3 Star Lounger
    Join Date
    Apr 2003
    Location
    Calgary, Alberta
    Posts
    327
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting Records Selected From Form (Access 2000)

    Awesome!. Thanks so much for your help [img]/forums/images/smilies/smile.gif[/img]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •