Microsoft
Software
Hardware
Network
Question : Copying multiple user selected records to a recordset
In a MS Access form, a user can select more than one record by clicking on first record's record selector and then, while holding the shift key down, clicking on nearby record's selector, which selects all the records between and including the two records.
Is there a way, using VB code, to copy these selected records to a recordset that can then be manipulated using code? I know how to use the CurrentRecord property of a RecordSetClone to copy a single selected record, but can't work out how to copy a block of selected records.
Answer : Copying multiple user selected records to a recordset
Here's an adapted function.
Call it from your form - it will return a DAO recordset with the required rows.
You'd call it as
Set rst = fLoadRstWithSelected(Me, "YourPKID")
Code follows:
Function fLoadRstWithSelected(pForm
As Access.Form, strPKName As String) As DAO.Recordset
Dim intBottom As Integer
Dim intTop As Integer
Dim intI As Integer
Dim strFilter As String
Dim rst As DAO.Recordset
With pForm
intTop = .SelTop
intBottom = .SelHeight + .SelTop - 1
End With
Set rst = pForm.RecordsetClone
With rst
If intTop > intBottom Then
strFilter = "1=0"
Else
For intI = intTop To intBottom
.AbsolutePosition = intI - 1
strFilter = strFilter & "," & .Fields(strPKName).Value
Next
strFilter = strPKName & " In (" & Mid(strFilter, 2) & ")"
End If
.Filter = strFilter
Set rst = .OpenRecordset
End With
Set fLoadRstWithSelected = rst
Set rst = Nothing
End Function
Bear in mind - that a selection is only maintained for as long as the form has the focus.
So if this is a subform - as soon as you attempt to click a button on the parent form - your selection will be lost.
Using a menu command or the exit event of the subform control will be options though.
Random Solutions
Access 2007 runtime - instaled from package solution wizard - trusted locations
Your changes could not be saved to "excel/word file name" because of a sharing violation. Try saving to different file.
MAPI Session - locate default signature text.
Number of days between two dates
VBA - Multiple outputs from one function
ASP.NET reading, creating Excel files
Click Context Menu, opened by mshtml.IHTMLElement
decrypt access database
I have 9 Cursore need to make one report
Using Range(Cells(r1,c1),Cells(r<wbr />2,c2)) instead of Range("A1:B2")