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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox SQL question

Status
Not open for further replies.

avagodro

Technical User
Aug 12, 2005
83
US
I have a listbox on my form which I have set to simple. I would like to have each selection as a separate record in the table. The table that the data is being stored in is tblResponses. The subform that has the listbox is frmResponses Subform, which is a subform on the subform frmQuestions which is a subform on frmQuestionaire. Hopefully I haven't lost you.
I have written the following code so far, that I temporarily have on a button control, using the OnClick event.

Dim db As Database: Set db = CurrentDb
Dim frm As Form
Dim ctl As Control
Dim varItem As Variant
Dim SQLstr As String
Set frm = Forms![frmQuestionaire]![frmQuestions]![frmResponses Subform].Form
Set ctl = frm!ListRspns

For Each varItem In ctl.ItemsSelected
db.Execute "INSERT INTO tblResponses(Rspns) VALUES ('"" & ctl.
itemdata(varItem) & ""');"
Next varItem

My problem is that I am still learning SQL and VB. I need the data from 4 fields on [frmResponses Subform] to save into the table. The Control names are ResponseDate, QstnID, AssociateRef, and Rspns. The field names in tblResponses are named the same.
Any suggestions on how to do that? I looked at the DAO option, and that is even more confusing to me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top