REPOST: AddNew record from multiselect listbox

G

Gary

Firstly, many thanks to Rod Scoullar for his support to
this point.

I am working with a form (SelectFrm)in which employee
names (EeID)are added from a bound multi-select listbox
into an unbound multiselect listbox. Course ID numbers
(ClsID) are also contained in the top of the form. I would
like to have code create a new record in the AttenTbl for
each employee in the unbound listbox (matching with the
ClsID for each).

I have code that I believe should work, but I get the
error message "Object or provider is not capable of
performing the requested operation." I will post the code
below.

Many thanks in advance to any who can assist.
Gary

===Start Code===
Private Sub CmdDone_Click()
On Error GoTo Err_CloseFrm_Click
Dim rs As New ADODB.Recordset
Dim strSQL As String
Dim varPtr As Variant
Dim lngClsID As Long
Dim lngEeID As Long

' open a recordset which contains records from the
AttenTbl table

strSQL = "Select * From AttenTbl"
rs.Open strSQL, CurrentProject.Connection

' set the value to the Class ID to add Attendees to

lngClsID = ClsID

' enumerate each item selected from the list

For Each varPtr In SelEeID.ItemsSelected
rs.AddNew ' add a new record to AttenTbl
lngEeID = SelEeID.Column(0, varPtr) ' where 0
is the column number corresponding to the EeID
rs!AttenClsID = lngClsID ' set the values for
the new record
rs!AttenEeID = lngEeID
rs.Update ' save the new record
Next

rs.Close

'DoCmd.Close

Exit_CmdDone_Click:
Exit Sub

Err_CloseFrm_Click:
MsgBox Err.Description
Resume Exit_CmdDone_Click

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top