Hello there, heres all my code to add questions from a listbox into a database table along with the answers assigned to a particular question.
VB Code:
Private Sub Command6_Click() Dim i As Integer Dim x As Integer i = List1.ListCount x = 0 Dim a As Integer Dim b As Integer Dim t As Integer t = 0 'rst2.Open "SELECT DISTINCT ansID from ss_table WHERE'" & Me.List1.ItemData(x) & "' = qnsID", cn, adOpenDynamic, adLockOptimistic b = 0 rst.Open "SELECT * from qnsdata_table", cn, adOpenDynamic, adLockOptimistic Do While Not x = i rst2.Open "SELECT DISTINCT Count(ansID) AS ans_count FROM ss_table WHERE '" & Me.List1.ItemData(x) & "' = qnsID", cn, adOpenDynamic, adLockOptimistic a = rst2!ans_count Me.Text1 = a Do While Not b = a rst3.Open "SELECT DISTINCT ansID FROM ss_table WHERE '" & Me.List1.ItemData(x) & "' = qnsID", cn, adOpenDynamic, adLockOptimistic rst1.Open "SELECT qnsdataID from autonumber", cn, adOpenDynamic, adLockOptimistic rst.AddNew rst!qnsDataID = "qd" & Right("000000" & CStr(CInt(rst1!qnsDataID) + 1), 6) rst!qnsID = Me.List1.ItemData(x) Do While Not rst3.EOF rst!ansID = rst3!ansID rst3.Update rst3.MoveNext Loop rst.Update rst1.Close rst3.Close rst1.Open "UPDATE autonumber SET qnsdataID = qnsdataID +1", cn, adOpenDynamic, adLockOptimistic b = b + 1 Loop rst2.Close x = x + 1 Loop rst.Close MsgBox "okiedokz" End Sub
(extracted from Command6_Click)VB Code:
Do While Not rst3.EOF rst!ansID = rst3!ansID rst3.Update rst3.MoveNext Loop
This doesn't appear to work, it is intended to add the list of answers assigned to a particular question.
For example, qns000001 has ans000001, ans000002 and ans000003. After clicking on the command button. only ans000003 is added to qns000001 'thrice'.
Any Suggestions?
Thank You
Astro




Reply With Quote