Append Record To Subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a multi-select list box populated by a query, and a subform linked to
the main form. I want to append each selection from the list box into the
subform.

What VB code do I use to put new record in the subform?



-Simon
 
Simon,
Please clarify.
Do you want to append the listbox selections represented records? If you
have a unique identifier as one of the fields in the listbox recordsource
query then us the "selected" property of the listbox in a loop and the
column number of the unique identifier to create the recordsource query of
the subform.
Need more info on how to do this?
 
Bill,

I have the code working that creates a new record in the subform, but
currently there's a problem because two records get created instead of one. I
think I know why it happens so I'm trying to find a solution. Anyway, the
code I'm using to create record from ListBox selections is as follows:

Dim rs As Recordset, db As Database, sql As String
Dim SelectedItem As Variant, count As Integer
sql = "Select * From Main"
Set db = CurrentDb
Set rs = db.OpenRecordset(sql, dbOpenDynaset)
count = 1
For Each SelectedItem In lstAdmin.ItemsSelected
rs.AddNew
rs![EmpID] = Me.cboEmp_Name.Value
rs![ManagerID] = Me.cboJob_Title.Value
rs![DeptID] = Me.cboDept.Value
rs("Doc_Number") = Me.lstAdmin.Column(0, SelectedItem)
If Not IsNull(Me.txtNotes) And count < 2 Then
rs("Notes") = Me.txtNotes.Value
End If
count = 2
rs.Update
Next

rs.Close
Set db = Nothing
Set rs = Nothing

The code does what it's supposed to do, but when I look inside the main
table I see the new record data, and just above it another record with
partial data filled in. That's a big problem for me right now. Can't figure
out why that's happening :-(

-Simon
 
Back
Top