I'm using the following code to insert data into two fields (Position and Courses for Position) into a table (PositionCoursestbl) from two list boxes.
However, when I make my selection from the listboxes and run the code, nothing happens
Here's the code:
For Each varItem In Me.List8.ItemsSelected
strItem = strItem & ",'" & Me.List8.ItemData(varItem) & "'"
Next varItem
If Len(strItem) <> 0 Then
strItem = Right(strItem, Len(strItem) - 1)
strItem = (" & strItem & ")
End If
For Each varItem In Me.List4.ItemsSelected
strLocation = strLocation & ",'" & Me.List4.ItemData(varItem) & "'"
Next varItem
If Len(strLocation) <> 0 Then
strLocation = Right(strLocation, Len(strLocation) - 1)
strLocation = (" & strLocation & ")
End If
strSQL = "INSERT INTO PositionCoursestbl ([Position], [Courses for Position])" & _
"VALUES ('" & strItem & "', '" & strLocation & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
Response = acDataErrAdded
End Sub
Any help would be great
Thanks,
David
However, when I make my selection from the listboxes and run the code, nothing happens
Here's the code:
For Each varItem In Me.List8.ItemsSelected
strItem = strItem & ",'" & Me.List8.ItemData(varItem) & "'"
Next varItem
If Len(strItem) <> 0 Then
strItem = Right(strItem, Len(strItem) - 1)
strItem = (" & strItem & ")
End If
For Each varItem In Me.List4.ItemsSelected
strLocation = strLocation & ",'" & Me.List4.ItemData(varItem) & "'"
Next varItem
If Len(strLocation) <> 0 Then
strLocation = Right(strLocation, Len(strLocation) - 1)
strLocation = (" & strLocation & ")
End If
strSQL = "INSERT INTO PositionCoursestbl ([Position], [Courses for Position])" & _
"VALUES ('" & strItem & "', '" & strLocation & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
Response = acDataErrAdded
End Sub
Any help would be great
Thanks,
David