Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing Listbox selections in table 1

Status
Not open for further replies.

jcg6

Technical User
Feb 18, 2002
50
US
I would like to use a multi-selection listbox to select values and store them in a table. I was able to do this in Access, but am having problems doing this in Project. Does anyone have any suggestions?? Thanks.
 
I've tried that and it doesn't work. Here is the code that I was using in my .mdb that doesn't work in my .adp...

Function CopySelected(frm As Form) As Integer 'This function inserts the selected emails into a table called EmailTmpTable
Dim ctlSource As Control
Dim ctlDest As Control
Dim intCurrentRow As Integer
Set ctlSource = frm!lstEmail

DoCmd.RunSQL "delete from EmailTmpTable"
For intCurrentRow = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(intCurrentRow) Then
DoCmd.RunSQL "insert into EmailTmpTable values (""" + ctlSource.Column(0, intCurrentRow) + """)"
End If
Next intCurrentRow

End Function
 

Dim cn As New ADODB.Connection, sql1 As String
Set cn = CurrentProject.Connection

cn.Execute "delete from EmailTmpTable"

'-Put in your loop the following.
sql1 = "insert into EmailTmpTable values ('"
+ ctlSource.Column(0, intCurrentRow) + "')"
cn.Execute sql1

'- when done
rs.Close
Set rs = Nothing
 
Thank you for your help. That code worked like a charm!! [smile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top