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!

Recordset Edit with Textbox entry 1

Status
Not open for further replies.

VBVines

MIS
Jun 11, 1999
98
US
I have a combo box and some text boxes. When I make a selection from the combo box the text boxes are populated with the other fields in the recordset. I need to be able to edit one of the fields and save the update. In DAO I used to be able to use .edit followed by the text boxes, their corresponding field names and then .update. How do I do it in ADO. Any ideas? Here is my existing code. Thanks

Private Sub Combo1_click()

Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset

With conn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\databases\ServersTest.mdb;Persist Security Info=False"
.Open
If .State = adStateOpen Then
'MsgBox "open"
Set rs = conn.Execute("SELECT * FROM equipment WHERE equipid = " + CStr(Combo1.ItemData(Combo1.ListIndex))) ', conn
If Not rs.EOF Then
Text1.Text = "" & rs("equipid")
Text2.Text = "" & rs("EquipmentName")
Text3.Text = "" & rs("Location")
Text4 = "" & rs("Service")
Infochanged = False
End If

rs.Close
Set rs = Nothing
Set conn = Nothing
End If
End With

End Sub

Private Sub Form_Load()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset

With conn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\databases\ServersTest.mdb;Persist Security Info=False"
.Open
If .State = adStateOpen Then
'MsgBox "open"
Set rs = conn.Execute("SELECT * FROM Equipment")
While Not rs.EOF
Combo1.AddItem rs("EquipID")
Combo1.ItemData(Combo1.NewIndex) = rs("EquipID")

rs.MoveNext
Wend

Combo1.ListIndex = 0

rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing

End If
End With
End Sub
aspvbwannab
 
Do you mean you want to write on a specific record is that it?
If so just open the record like for example:

rsRecordset.Open "SELECT....", conn, adOpenKeyset, adLockOptimistic

then just make

rsRecordset!Field = "Whatever you want"
rsRecordset.Update

That should work.

Tell me if you are still having problems with that.
 
Daimou THanks, What I am looking for is a way for my end users to edit recordsets so after they pick an item in the combo box and the associated text boxes are populated, they can edit one or more text boxes and then hit a save button that will save their updates. aspvbwannab
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top