Hello there,

below are the codes i've written to record all the items (which are qnsID) in list box (List1) into qnsdata_table.

VB Code:
  1. Private Sub Command6_Click()
  2. Dim x As Integer
  3. Dim y As Integer
  4.  
  5. x = List1.ListCount
  6. y = 0
  7.  
  8. rst.Open "SELECT * from qnsdata_table", cn, adOpenDynamic, adLockOptimistic
  9.  
  10. Do While Not y = x
  11.     rst1.Open "SELECT qnsdataID from autonumber", cn, adOpenDynamic, adLockOptimistic
  12.     rst.AddNew
  13.     rst!qnsDataID = "qd" & Right("000000" & CStr(CInt(rst1!qnsDataID) + 1), 6)
  14.     rst!qnsID = Me.List1.ItemData(y)
  15.     rst.Update
  16.     rst1.Close
  17.     rst1.Open "UPDATE autonumber SET qnsdataID = qnsdataID +1", cn, adOpenDynamic, adLockOptimistic
  18.     y = y + 1
  19. Loop
  20.  
  21. rst.Close
  22. End Sub

The problem is that for each item (qnsID) there are several assigned (ansID) and i need them to be recorded along with the qnsID, into qnsdata_table.
______________________________
| qnsdataID | qnsID | ansID |
-----------------------------------
| qd0001 | qns0002 | ans0012 |
| qd0002 | qns0002 | ans0016 |
| qd0003 | qns0002 | ans0001 |
------------------------------------

In this case, should i have another Do While Loop within the current Loop, to find out how many 'ansID' there are which are assigned to each 'qnsID'.

I've tried

VB Code:
  1. rst2.Open "SELECT Count(ansID) AS ansID_count FROM ans_table where....(conditions)
  2.  
  3. Me.Text2 = rst2!ansID_count         '(ive no idea where to store the count) value)
  4.  
  5. a = Me.Text2                              '(shift value into variable a)
  6. b = 0

and here goes another loop, but it didn't work.

Need some advice and comments from you guys =)

Thanks a million.

Astro