help me update my database..
when i click edit it will add a new record..
i want to update a record..

to edit a new record it will be base on the cutsomer's nameu

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


Set conn = New ADODB.Connection

conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
            & "SERVER=localhost;" _
            & "DATABASE=database1;" _
            & "UID=root;" _
            & "PWD=;" _
            & "OPTION=" & 1 + 2 + 8 + 32 + 2048 + 16384
 
conn.CursorLocation = adUseClient
conn.Open


RS.Open "SELECT * from Phonebook", conn, adOpenStatic, adLockOptimistic
RS.Update
 
            txtName.Text = RS!Customers_Name
            RS!Address = txtAddress.Text
            RS!Mobile = txtMobile.Text
            RS!Telephone = txtTelephone.Text


RS.Update
MsgBox "Record has been Saved", vbInformation
RS.Close
conn.Close

Hi,

Change the code to :

To Add record:

RS.Open "SELECT * from Phonebook", conn, adOpenDynamic, adLockOptimistic
RS.AddNew
RS!Customers_Name = txtName.Text
RS!Address = txtAddress.Text
RS!Mobile = txtMobile.Text
RS!Telephone = txtTelephone.Text
RS.Update

To Edit the record:

RS.Open "SELECT * from Phonebook Where Customer_Name = '" & txtName.Text & "'", conn, adOpenDynamic, adLockOptimistic
If RS.EOF Then
    RS.AddNew   'Record Not Found so Adding New
    RS!Customers_Name = txtName.Text
Else
    RS.MoveFirst
End If
RS!Address = txtAddress.Text
RS!Mobile = txtMobile.Text
RS!Telephone = txtTelephone.Text
RS.Update

Regards
Veena

Edited 5 Years Ago by QVeen72: n/a

its working tnx but 1 more problem..
the saved record will be blank it wont show up the saved record you will add again the address,mobile and telephone number

This question has already been answered. Start a new discussion instead.