[RESOLVED] MSFlexgrid - Refreshing data on grid.
I am new to VB6.
I have a MsFlexgrid that loads data from an Access table. I have an Edit button on the same form as the MSFlexgrid control. This Edit button calls a 2nd "Edit" form.
I can Edit a record/row just fine in the Edit Form. It updates the Access table record, but does not refresh on the MSFlexgrid after exiting the Edit form.
The row contains the original value. If I edit it a second time, the Edit information box has the changed data.
In the "main form" in the Form_Load() I have:
Call UpdateGrid
' This upates the MSFlexgrid control from a recordset.
When I exit the Edit Form, I update the Access table and from
here Call "Main Form".UpdateGrid (Same sub)
What trick am I missing with the MSFlexgrid control?
Here is some of the UpdateGrid code if that matters:
Code:
Public Sub UpdateGrid()
Dim strSql As String
Dim intRecordCount As Integer
Dim intTheRow As Integer
strSql = "Select name, address from names'
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = adoSupplier
.CursorType = adOpenKeyset
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Source = strSql
End With
rs.Open
intTheRow = 0
With fgrdNames
.TextMatrix(0, 0) = "Names"
.TextMatrix(0, 1) = "Address"
Do Until rs.EOF
intTheRow = intTheRow + 1
.TextMatrix(intTheRow, 0) = rstSupplier.Fields("name").Value
.TextMatrix(intTheRow, 1) = rstSupplier.Fields("address").Value
rs..MoveNext
Loop
End With
Re: MSFlexgrid - Refreshing data on grid.
When you exit your Edit form and call UpdateGrid, did you check what's happening inside the loop? Did you add a brakpoint to see if it was looping something?
Also that UpdateGrid is present just in the main form, isn't it?
Re: MSFlexgrid - Refreshing data on grid.
Yes I have checked.
It definitely gets called and loops through the recordset a 2nd time (when existing the edit form).
Any ideas on why it is not refreshed on the screen in the MSFlexgid?
Re: MSFlexgrid - Refreshing data on grid.
Do you have two periods here or is that a mistake?
There should only be one.
Re: MSFlexgrid - Refreshing data on grid.
There is only one in the actual code. My mistake. I hit key again after I pasted the code.
Re: MSFlexgrid - Refreshing data on grid.
Is the connection adoSupplier the same connection used by the Edit form? Are you using the Jet Provider? Jet caches writes to the database. Only recordsets opened on the same connection will see the updates immediately. If you are using a different connection you will need to wait a few seconds before retrieving the data.
If adoSupplier is the same connection used by both, try this change
VB Code:
With rs
[B]Set [/B] .ActiveConnection = adoSupplier
.CursorType = adOpenKeyset
Re: MSFlexgrid - Refreshing data on grid.
brucevde,
You are the man.
Thank you. I was using a different Connection and it was "caching". I could not figure out why this was working in "debug" mode, but not real time.
I passed the same "adoConnection" to the Edit form and it works now.
I have been beating my head against a wall for over 3 hours trying different things.
Thanks again. I can only hope that the favor will be returned to you 10 fold.
Scott
P.S. I consider this one resolved, but do not know how to "tag/mark" it as such. :thumb:
Re: MSFlexgrid - Refreshing data on grid.
Quote:
Originally Posted by ScottMatthews
brucevde,
You are the man.
Thank you. I was using a different Connection and it was "caching". I could not figure out why this was working in "debug" mode, but not real time.
I passed the same "adoConnection" to the Edit form and it works now.
I have been beating my head against a wall for over 3 hours trying different things.
Thanks again. I can only hope that the favor will be returned to you 10 fold.
Scott
P.S. I consider this one resolved, but do not know how to "tag/mark" it as such. :thumb:
Pull down the thread tools Menu and click "mark thread Resolved".
Also, when you get to 20 posts, you will have 1 reputation power, then you could get back to this post and rate Bruce's post, it's a nice way to thank the person who helped you. ;)