I was referred to an example database for adding multiple table entries using a list box. I have it all set up, and this is the code I'm using for the command button to add the entries:
Private Sub Command9_Click()
Dim strSQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim ctl As Control
Dim varItem As Variant
On Error GoTo ErrorHandler
Set db = CurrentDb()
Set rs = db.OpenRecordset("Marine Gig Count", dbOpenDynaset, dbAppendOnly)
'make sure a selection has been made
If Me.ListMarines.ItemsSelected.Count = 0 Then
MsgBox "Must select at least 1 employee"
Exit Sub
End If
'add selected value(s) to table
Set ctl = Me.ListMarines
For Each varItem In ctl.ItemsSelected
rs.AddNew
rs!Rank = ctl.Column(1)
rs!LastName = ctl.Column(2)
rs!FirstName = ctl.Column(3)
rs!MI = ctl.Column(4)
rs!EventName = Me.EventName
rs!EventType = Me.EventType
rs!EventDate = Me.EventDate
rs.Update
Next varItem
ExitHandler:
Set rs = Nothing
Set db = Nothing
Exit Sub
ErrorHandler:
Select Case Err
Case Else
MsgBox Err.Description
DoCmd.Hourglass False
Resume ExitHandler
End Select
End Sub
What it ends up doing is just adding the information for the last item in the list box I clicked, and doing it for the number of entries I clicked on (i.e. I click five names and I get five duplicate entries with the info of the last person I clicked on). Is this a programming thing, or is there some setting I need to change on the list box?