Results 1 to 5 of 5
  1. #1
    GeorgeJ is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    67

    How VB can know what records and how many in a form have been selected

    I have a tabular form with record selectors. Suppose I click in one of the selectors, then hold the shift button and select the two records below the first one I selected. What would the code look like which would precede the following code to make it give the right answer




    Dim NumSelected as Integer, FirstSelected as Integer

    'What code goes here ?'

    Msgbox "You selected " & NumSelected & " records, starting with record # " & FirstSelected


    Thanks in advance

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Use SelHeight form property.

    NumSelected = Me.SelHeight

    SelTop will give the first record position: Me.SelTop
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848

  4. #4
    GeorgeJ is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    67
    Thank you. I didn't know about either of them.

    Seltop works fine. I am having a problem with SelHeight, which always returns 0. I put a button "Command7" on my form and the click code is

    Private Sub Command7_Click()
    MsgBox Me.SelTop & ", " & Me.SelHeight
    End Sub

    I put the cursor on the second record selector, and click, then hold down the shift key, move the cursor down 1 and click again. Now the selectors for records 2 and 3 are black. I move the cursor to the button "Command7" and click. The message I get is

    2, 0

    and I notice that the act of moving the cursor from the record selectors and clicking Command7 unblackens the record selectors. The small black triangle remains in the selector for record 2. So it indeed looks like only this record is selected.

    Any suggestions. I eventually want to have code in Comand7 do something with all the selected records, but it seems that the act of clicking on Command7 cancels the selection for all but the current record.

    Any suggestions?

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    I have used this code only once and it was actually written by someone else. It involves a form/subform arrangement. Records are selected in subform but code is behind main form. Apparently need global module variables.

    Code:
    Option Compare Database
    Option Explicit
    Dim intHeight As Integer    'stores value for number of test records selected for deletion
    Dim intTop As Integer   'stores value for position of the first selected record in Tests recordset
    
    Private Sub ctrTests_Exit(Cancel As Integer)
    'sets module variables starting values for use in deleting selected tests
    intHeight = Me.ctrTests.Form.SelHeight
    intTop = Me.ctrTests.Form.SelTop
    End Sub
    
    Private Sub RemoveTest()
    'Cascade deletions out to individual data tables then delete from Tests table
    On Error GoTo err_Proc
    With Me.ctrTests.Form.RecordsetClone
    If .RecordCount < 1 Then
        MsgBox "No tests have been saved.  Delete action canceled.", , "RemoveTest Error"
    ElseIf intHeight < 1 Then
        MsgBox "No tests have been selected.  Delete action canceled.", , "RemoveTest Error"
    Else
    ...
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 02-12-2015, 04:17 PM
  2. Replies: 11
    Last Post: 12-08-2014, 08:51 AM
  3. Replies: 9
    Last Post: 08-19-2014, 12:41 PM
  4. Replies: 18
    Last Post: 01-27-2012, 12:53 PM
  5. Replies: 7
    Last Post: 02-25-2010, 12:32 PM

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