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

Updating a recordset with VB6 ADO 1

Status
Not open for further replies.

VBVines

MIS
Jun 11, 1999
98
US
I am trying to update a recordset after I edit it and the only thing that changes is the first recordset. The one I edited stays the same. Nothing gets edited but the first recordset. This is the code I am using, if someone could help out that would be way cool. I set a public boolean variable called infochanged.
=====
Private Sub CmdSave_Click()
If Infochanged Then
MsgBox "true"
Dim rs As ADODB.Recordset
strcnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\databases\ServersTest.mdb;Persist Security Info=False"
Set rs = New ADODB.Recordset
rs.CursorType = adOpenDynamic
rs.LockType = adLockPessimistic
rs.Open "Select * From equipment", strcnn, , , adCmdText
rs!EquipmentName = "'" & Text2.Text & "'"
rs!Location = "'" & Text3.Text & "'"
rs!Service = "'" & Text4.Text & "'"
rs.Update
Else
MsgBox "false"
End If
rs.Close
Set rs = Nothing
Set conn = Nothing

End Sub aspvbwannab
 
When set the property, you're doing so for the current record only. In order to do the same for each record,you'll have to loop:

Code:
  rs.Open "Select * From equipment", strcnn, , , adCmdText
  
  sEquipmentName = "'" & Text2.Text & "'"
  sLocation = "'" & Text3.Text & "'"
  sService = "'" & Text4.Text & "'"
  Do Until rs.Eof
    rs!EquipmentName = sEquipmentName
    rs!Location =  sLocation
    rs!Service = sService
    rs.Update
    rs.MoveNext
  Loop

But this is obviously setting each record's fields to the same values. If you're really trying to do that, consider a straight SQL update query, e.g.,

sSQL = "UPDATE Equipment SET EquipmentName = " & sEquipmentName & ", Location = " & sLocation & ", sService = " & sService

This will have the db do it far more efficiently via a set update rather than fetching, looping through, then returning a recordset for an update.

HTH.
-Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top