A.D.Tejpal
adtp at airtelmail.in
Thu Mar 5 23:32:47 CST 2009
David, My sample db's mentioned below, might be of interest to you: (a) Form_SubformAsListBox (b) Form_TrackBulkSelectionsInDataSheet (c) FormsSelectedBlockInDatasheet These are available at Rogers Access Library. Link - http://www.rogersaccesslibrary.com/forum/forum_topics.asp?FID=45 You could adapt the underlying approach suitably, for your specific needs. Best wishes, A.D. Tejpal ------------ ----- Original Message ----- From: David McAfee To: Access Developers discussion and problem solving Sent: Friday, March 06, 2009 02:37 Subject: [AccessD] How do I refer to a range of selected records in asubform datasheet? I have a read only subform in datasheet mode. I've switched from using a list box, because the user wanted sorting, column width, filtering and a couple of other options. With the list box, if the user wanted to update a bunch of records, I would do something like this: The user select the listbox row(s) then presses a command button. Code in the onClick event would perform a task similar to: 'Inserting records from a listbox (Looping through the listbox) If Me.lstTitles.ItemsSelected.Count > 0 Then Dim varIndex As Variant Dim lRecordsAffected As Long Dim Cnn As ADODB.Connection Dim Cmd As ADODB.Command Set Cnn = New ADODB.Connection Set Cnn = CurrentProject.Connection For Each varIndex In Me.lstAddrLocOrContact.ItemsSelected 'For every item selected in list box Set Cmd = New ADODB.Command With Cmd Set .ActiveConnection = Cnn .CommandType = adCmdStoredProc .CommandText = "stp_001B3_AddContactTitles" .Parameters.Append .CreateParameter("@ctcID", adInteger, adParamInput, , Me.strCtcID) '.Parameters.Append .CreateParameter("@addrLocID", adInteger, adParamInput, , Me.lstAddrLoc.Column(3, varIndex)) .Parameters.Append .CreateParameter("@addrID", adInteger, adParamInput, , Me.strAddrID) Set .ActiveConnection = Cnn .Execute lRecordsAffected End With Set Cmd = Nothing Next 'Loop to the next selected item Cnn.Close Set Cnn = Nothing End If I know I can reference the form!sbform!PKID but do I have to loop the the whole recordset and check if record is selected? I'm getting rusty with access. :) David