Saving data to table from form w/ Multi-Select Listbox

adidashawn6

New member
Local time
Today, 08:13
Joined
Jan 23, 2012
Messages
8
I am working with a database that records "Journal Entries" that supervisors create for their direct report employees. I have just created a new Entry form that allows the supervisor to select multiple employees through the use of a multi-select listbox. I have code that will enter the "Journal Entry" for all of the employees that the supervisor selects, but I am also getting a 'Blank' entry as well. What I mean by a blank entry is that there is always an entry made that has a blank field for the employee’s name. Any help in preventing this 'Blank' entry would be greatly appreciated. Here is the code that I am currently using:

Code:
Dim varValue As Variant
 
With Me.AgentName
    For Each varValue In .ItemsSelected
         CurrentDb.Execute "INSERT INTO [Journal Data] ([Agent], [Coach], [Action_Date], [Action_Reason], [Journal_Entry], [Entry_Date], [Entered_By]) Values " & _
                    "('" & Me.AgentName.Column(0, varValue) & "','" & Me.CoachName & "',#" & Me.ActionDate & "#,'" & Me.JournalReasonDropDown & "','" & Me.JournalMemo & "',#" & Me.CurrentDate & "#,'" & Me.Text34 & "')"
   Next
End With
 
Is the form bound to the table?
 
Yes, it is bound to the [Journal Data] table
 
That is likely the source of your extra record. Since you're adding records via code, you typically would want the form to be unbound.
 

Users who are viewing this thread

Back
Top Bottom