0

hi i have been able to update a database using the following code
Option Explicit
Dim conn As ADODB.Connection, rec1 As ADODB.Recordset
Dim esql1 As String

Private Sub Command1_Click()
On Error GoTo 2
If Text1 = "" Then
Command1.Visible = False
Command2.Visible = True
Exit Sub
End If
rec1.AddNew
rec1.Fields(1) = Text1
rec1.Update
GetText
Exit Sub
2
MsgBox ("Duplicate Value")
End Sub

Private Sub Form_Load()
Set conn = New ADODB.Connection
Set rec1 = New ADODB.Recordset
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\shnd\Project.mdb;Persist Security Info=False"
conn.Open
esql1 = "select * from Header"
rec1.Open (esql1), conn, adOpenDynamic, adLockOptimistic
GetText
End Sub

Private Sub GetText()
Do While Not rec1.EOF
List1.AddItem rec1.Fields(1)
rec1.MoveNext
Loop
End Sub


The only problem i am havin is that after clicking the update command the listbox displays the new data twice.. it has to do it once

3
Contributors
3
Replies
5
Views
8 Years
Discussion Span
Last Post by vb5prgrmr
0

Private Sub GetText()
List1.Clear
Do While Not rec1.EOF
List1.AddItem rec1.Fields(1)
rec1.MoveNext
Loop
End Sub

try this..

0

no it didn't work it only clears the listbox and again displays the new entry twice

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.