okay.

Here's my problem.
I have a form in which a Microsoft Hierarchical Flex Gid (fgdCompany) is used to display records taken from a database to relavent textboxes on the same form.
When a record from fgdCompany is clicked, then the data in that record is shown on the textboxes.
I have a button called cmdUpdate which should do the following when clicked :
Once, the record is diplayed on the text boxes, a change could be made to it.
And when cmdUpdate is clicked it should save the changes it made to that record and display the new updated record on fgdCompany.
My problem is, it always saves the changes made to the first record in fgdCompany. Not the record I want to be changed.
Please help me..... Code used for cmdUpdate is given below.

  Dim rsCompany As New ADODB.Recordset
  Dim cn As New ADODB.Connection
  Dim strSQL As String

  cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                        "Data Source=" & App.Path & "\Luckshan Tours & Travels.mdb;" & _
                        "Persist Security Info:False"

  cn.Open

  strSQL = "SELECT [Company].* FROM [Company]"
  rsCompany.Open strSQL, cn, adOpenStatic, adLockPessimistic

  rsCompany.Fields("Address") = txtAddress
  rsCompany.Fields("Telephone Numbers") = txtTelephoneNo
  rsCompany.Fields("Vehicles Registered") = txtVehiclesReg

  rsCompany.Update

  MsgBox "Changes Saved."

  Set fgdCompany.DataSource = rsCompany

  rsCompany.Update

Recommended Answers

All 4 Replies

it seems that u have not specified the row number on which the update has to take place. By default, it will update the first row. try using a loop to get the row number and then update the database.

First -

strSQL = "SELECT [Company].* FROM [Company]"

This will select ALL records from your table Company. You did not specify which company you want to edit...

First get the record from the row the user clicked on in your datagrid. Lets assume you have the Comapny Id in coloumn 1 AND the user clicked on a row (get row clicked on and then get the id from coloumn), use the following -

Dim xId As String, xRow As Integer

 xRow = mshFlexgrid.Row
 xId = mshFlexgrid.TextMatrix(xRow, 1)

This will now return an Id to search your table -

strSQL = "SELECT [Company].* FROM [Company] WHERE id ='" & xId & "'"

and voila, problem solved :)

@AndreRet thnx a lot buddy! worked great!! =D thnx again...

commented: Only a pleasure :) +12

No problem. Glad your problem got solved ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.