944,035 Members | Top Members by Rank

Ad:
Oct 26th, 2009
0

Reading from a database

Expand Post »
I have a subscription system that i have developed. the system is supposed to automatically subtract the number of copies given to a client every monthend as per request they made of the copies required upon joining. my problem is i cant make my code run through my database so that it can subtract from every record....instaed it can deal with one record at a time. i cant manually subtract because the records at one time are going to reach thousands. i justa want it to automatically subtract from all fields when a button is clicked.

i have een trying to use this code but its not working.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. With rc
  2. .ActiveConnection = deSub.conn
  3. .LockType = adLockOptimistic
  4. .Source = "select * from cooperatesubs"
  5. .Open
  6. End With
  7. z = rc.Fields("numberofcopies")
  8. Do Until rc.EOF
  9. rc.AddNew
  10. rc.Fields("numberofcopies") = z
  11. rc.Fields("copiesgiven") = y
  12. rc.Fields("copiesremaining") = z - y
  13. rc.Update
  14. rc.MoveNext
  15. Loop
  16. Exit Sub
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Israelsimba is offline Offline
41 posts
since Oct 2009
Oct 26th, 2009
0
Re: Reading from a database
Try the following -

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. With rc
  2. .ActiveConnection = deSub.conn
  3. .LockType = adLockOptimistic
  4. .Source = "select * from cooperatesubs"
  5. .Open
  6. End With
  7.  
  8. Dim w As Integer
  9. Dim x As Integer
  10. Dim y As Integer
  11. Dim z As Integer
  12.  
  13. Do Until rc.EOF = True
  14.  
  15. y = rc.Fields("copiesgiven")
  16. z = rc.Fields("numberofcopies")
  17. x = z - y
  18. w = y + 1
  19.  
  20. rc.AddNew
  21. 'rc.Fields("numberofcopies") = z This will not change, for it is a set number, correct?
  22. rc.Fields("copiesgiven") = w
  23. rc.Fields("copiesremaining") = x
  24. rc.Update
  25. rc.MoveNext
  26. Loop
  27. Exit Sub
Reputation Points: 329
Solved Threads: 347
Senior Poster
AndreRet is offline Offline
3,700 posts
since Jan 2008
Nov 7th, 2009
0
Re: Reading from a database
i strongly believe the problem is with the
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. .movenext
part. its not moving to the next record wich makes it effective on one row only and fails to run through the database.
i was wondering isnt there any other way of doing this besides this one
thanx you
Reputation Points: 10
Solved Threads: 0
Light Poster
Israelsimba is offline Offline
41 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Try-Catch feature for VB6, VBA, VBScript
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: If then Statement in excel using data in 2-3 columns





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC