Article ID: 148393
Article Last Modified on 1/19/2007
Function DisplaySelectedCompanyNames()
Dim i As Long
Dim F As Form
Dim RS As Recordset
' Get the form and its recordset.
Set F = Forms![Customers1]
Set RS = F.RecordsetClone
' Move to the first record in the recordset.
RS.MoveFirst
' Move to the first selected record.
RS.Move F.SelTop - 1
' Enumerate the list of selected records presenting
' the CompanyName field in a message box.
For i = 1 To F.SelHeight
MsgBox RS![CompanyName]
RS.MoveNext
Next i
End Function
Macro Name Action
----------------------
{F5} RunCode
AutoKeys Actions
------------------------------------------------
RunCode
Function Name: =DisplaySelectedCompanyNames()
In the Customize dialog box, click the Commands tab and select
"All Macros." Under Commands, drag "AutoKeys.{F5}" from the Commands
list to an empty space on the toolbar, and then click Close.
In the Customize Toolbars dialog box, under Categories, select "All
Macros." Under Objects, drag "AutoKeys.{F5}" from the Objects list to
an empty space on the toolbar, and then click Close.
Dim MySelTop As Long
Dim MySelHeight As Long
Dim MySelForm As Form
Dim fMouseDown As Integer
Function SelRecord(F As Form, MouseEvent As String)
Select Case MouseEvent
Case "Move"
' Store the form and the form's Sel property settings
' in the MySel variables ONLY if mouse down has not
' occurred.
If fMouseDown = True Then Exit Function
Set MySelForm = F
MySelTop = F.SelTop
MySelHeight = F.SelHeight
Case "Down"
' Set flag indicating the mouse button has been pushed.
fMouseDown = True
Case "Up"
' Reset the flag for the next time around.
fMouseDown = False
End Select
End Function
Public Sub SelRestore()
Debug.Print "got into Restore"
' Restore the form's Sel property settings with the values
' stored in the MySel variables.
MySelForm.SelTop = MySelTop
MySelForm.SelHeight = MySelHeight
End Sub
Name: cmdSelectedCompanyNames
Caption: Display Selected Company Names
Width: 2"
OnClick: [Event Procedure]
OnMouseDown: =SelRecord([Form],"Down")
OnMouseMove: =SelRecord([Form],"Move")
OnMouseUp: =SelRecord([Form],"Up")
Private Sub cmdSelectedCompanyNames_Click()
Dim X
' Restore the lost selection.
SelRestore
' Enumerate the list of selected company names.
X = DisplaySelectedCompanyNames()
End Sub
OnMouseDown: =SelRecord([Orders Subform].[Form],"Down") OnMouseMove: =SelRecord([Orders Subform].[Form],"Move") OnMouseUp: =SelRecord([Orders Subform].[Form],"Up")
Additional query words: multi-selection multiple
Keywords: kbhowto KB148393