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

updating ado recordsets 1

Status
Not open for further replies.

VBVines

MIS
Jun 11, 1999
98
US
I edit one of the text boxes that represents a field in my database and hit the save button that contains this code. The only record that gets updated is the first row of the database. None of the others, when I make another edit again only the first row. Can someone tell me if some of my code is bad. Thanks

Private Sub CmdSave_Click()
Dim rs As ADODB.Recordset
Dim Ssql As String

conn = "Provider=SQLOLEDB.1;Password=admin;Persist Security Info=True;UserID=tk;Initial Catalog=pubs;Data Source=ZSPOTK"
Set rs = New ADODB.Recordset
Ssql = "Select * from publishers Where country = '" & Text5.Text & "'"

rs.Open Ssql, conn, adOpenKeyset, adLockOptimistic, adCmdText

If rs.EOF = True Then
rs.MovePrevious
End If
If rs.bof= True Then
rs.movenext
End If

rs!Pub_name = Text1
rs!city = Text2
rs!State = Text3
rs!country = Text4
rs.Update

rs.Close
End Sub aspvbwannab
 
In your code you are only updating the record you are on. If you do not move the recordset none of the other records will be affected. Maybe you should try a SQL update:
sSQL = "UPDATE PUBLISHERS SET STATE = '" & Text3 & '" & _
"WHERE COUNTRY = '" & Text5 & "'"

I do not know which field you wanted to update so this is just an example
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top