[AccessD] Selected Records on a Continuous Form

Gustav Brock gustav at cactus.dk
Sat Oct 25 03:59:21 CDT 2008


Hi Rocky

A.D is right, this may not be as simple as it seems.

If you mark records and push Delete, selection remains and you can read SelTop and SelHeight.
If you push a button, selection is lost as the focus moves.

However, a piece of code I played with years ago lets you keep the selection and reapply it:

<code>
Option Compare Database
Option Explicit

Dim lngSelTop       As Long
Dim lngSelHeight    As Long
Dim booCancelDelete As Boolean

Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)

  Cancel = booCancelDelete
  
End Sub

Private Sub Form_Current()

  lngSelHeight = 0
  Me!btnDelete.Enabled = False

End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  
  lngSelTop = Me.SelTop
  lngSelHeight = Me.SelHeight
  Me!btnDelete.Enabled = True

End Sub

Private Sub btnDelete_Click()

  If lngSelHeight > 0 Then
    ' Repaint selection of rows.
    Me.SelTop = lngSelTop
    Me.SelHeight = lngSelHeight
    
    Call DeleteRecords
  End If
  
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

  If KeyCode = vbKeyDelete Then
    Call DeleteRecords
  End If
  
End Sub

Private Sub DeleteRecords()
  
  Dim strPrompt As String
  
  strPrompt = "Delete record" & Str(lngSelTop) & _
    IIf(lngSelHeight = 1, vbNullString, " to" & Str(lngSelTop + lngSelHeight - 1)) & "?"
  If MsgBox(strPrompt, vbQuestion + vbOKCancel + vbDefaultButton2) = vbOK Then
    ' Delete record(s).
  Else
    booCancelDelete = True
  End If

End Sub
</code>

Note that this does not count for selection of records with the navigation keys combos: Ctrl+Shift+PgUp and  Ctrl+Shift+PgDn.
You would have to apply code for this as well. And fine tune as well - if you press Delete and cancel, selection remains as it should but the btnDelete stays disabled ...

Anyway, I'm sure you get the idea.

/gustav


>>> adtp at airtelmail.in 25-10-2008 08:27 >>>
Rocky,

    Volatile nature of SelHeight property constitutes a typical hurdle faced in capturing the status of selected records on continuous form. This is because the erstwhile selection as well as the value of SelHeight is lost as soon you click a command button on the form.

    Simplest course of action would be to use bound check box for selecting / de-selecting records.

    If you wish to track the selection status without resorting to bound check box, my sample db named ContFormsKeyNavAndHighLightMultiSelect might be of interest to you. It is available at Rogers Access Library (other developers library). Link - 

http://www.rogersaccesslibrary.com/forum/forum_topics.asp?FID=45 


    This db demonstrates identification of selected records on a continuous form. Selection of scattered non-contiguous blocks of records is also permitted. ID's of all records selected in current session are displayed in a text box in form footer and remain intact till cleared by double click on any record.

Best wishes,
A.D. Tejpal
------------

  ----- Original Message ----- 
  From: Rocky Smolin at Beach Access Software 
  To: 'Access Developers discussion and problem solving' 
  Sent: Friday, October 24, 2008 21:36
  Subject: [AccessD] Selected Records on a Continuous Form


  Dear List:

  Is there a way to determine which records on a continuous form have been
  selected using the record selector boxes.
   
  For complicated reasons I cannot use the Access delete records thing - had
  to put a 'Delete Selected Record' button on the form.  That works OK and
  through code I delete the selected record and requery the form.
   
  Now the user wants to be able to select multiple records like they could
  before.  I can use my code to delete the selected records if I can determine
  which ones are selected.
   
  But there's not .Selected property I can find for recordsets like there is
  with multi-select list boxes although it appears that you can only select
  contiguous records on a continuous form using the shift key. Control key to
  select non-contiguous forms doesn't seem to to work.
   
  Is there such a property or a way to find out which records have been
  selected?
   
  MTIA
   
  Rocky Smolin





More information about the AccessD mailing list