Using the Control Key on a Listbox

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I have a form that the users use to define attendees for tabulation of
courses. On the one side is a filtered listbox that lists all the employees,
and on the other side of the form is a listbox that gets filled when a button
is pressed. The user is to select the employees that will be attending from
the first listbox and then press the input button to transfer those employee
names to the second listbox. I have had a request by one user to be able to
block transfer employees by using the control keys. I have noticed that
holding down the control key results in being able to block select employees
in the listbox, but when the transfer button is pressed only the last clicked
on employee gets transfered. How might I assure that all those employees in
the block selected get moved?

the code for the transfer button is as follows:

Private Sub MoveToAttendees_Click()
On Error GoTo MoveToAttendeesError

Dim MyDB As Database
Dim MyStudents As Recordset
Dim MyEmployees As Recordset
Dim vExpiryDate As String
Dim I, X As Integer

Set MyDB = CurrentDb
Set MyStudents = MyDB.OpenRecordset("SessionAttendance")

DoCmd.Hourglass True

If [Forms]![CoursesMain]![RecertPeriod] <> 99 Then
vExpiryDate = DateAdd("d", (365 *
[Forms]![CoursesMain]![RecertPeriod]), Me.Date)
Else
vExpiryDate = "01-Jan-2999"
End If

For I = 0 To Me.EmployeesList.ListCount - 1
'MsgBox "on item # " & I
If Me!EmployeesList.Selected(I) = True Then
With MyStudents
.AddNew
!CourseID = Me.CourseID
!SessionID = Me.SessionID
!EmpID = Me.EmployeesList.ItemData(I)
!Attended = True
.Update
AttendAdd Forms!CoursesMain!TrainingType, Me.CourseID,
Me.SessionID, Me.EmployeesList.ItemData(I), Me.Date, vExpiryDate
End With

End If
Next I

MyStudents.Close
MyDB.Close
Set MyDB = Nothing
Form.Refresh
DoCmd.Hourglass False
Me.MoveToAttendees.DefaultValue = False
Exit Sub

MoveToAttendeesError:
If err.Number = 3022 Then 'Duplicate record
MsgBox "The employee '" & Me!EmployeesList.Column(2, I) & " " &
Me!EmployeesList.Column(1, I) & _
"' is already attending this session."
End If

If err.Number = 3140 Then Resume Next
'Else
'MsgBox Error$ & err.Number
'End If
Form.Refresh
MyStudents.Close
MyDB.Close
Set MyDB = Nothing
DoCmd.Hourglass False
Me.MoveToAttendees.DefaultValue = False
End Sub

.



Relevant Pages

  • how to double click a list box item to add to subform
    ... I would like my user to be able to add those attending an event to a subform by doubleclicking a member in a listbox on the main form. ... AttendID (primary key, autonumber) ...
    (microsoft.public.access.formscoding)
  • Re: Best design for this problem......
    ... I would use a userform with two listboxes, a combobox and two command ... One listbox would be populated with the names of the employees from a table ...
    (microsoft.public.word.vba.general)
  • Re: Listbox on Excel Userform
    ... Look for the match and plop the info from each match into that listbox. ... Private Sub CommandButton1_Click ... that the ListBox then lists all other employees names that are in ...
    (microsoft.public.excel.programming)
  • Re: Adding records to a table using a listbox
    ... As with other list boxes, you could implement this with the ListBox row ... To find out who attended a meeting. ... Listbox 2 = to list employees names of who attended a meeting. ...
    (comp.databases.ms-access)
  • Re: Requery instruction doesnt refresh data in list box in AC2K
    ... What is the Row Source for the listbox? ... > box on the form "Employees" to show the new inserted employee. ... > for microsoft to fool around with a developer's mind like that. ...
    (microsoft.public.access.formscoding)