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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refreshing a DataGrid

Status
Not open for further replies.

splaisance

Programmer
Jul 2, 2001
67
US
I have an odd situation that I hope someone can help with.

I have 2 DataGrids on a form. The first has detail information and the second has totals.
When the user changes an amount in the first grid, I want the cooresponding total to change in the second grid.

In the Grid1_AfterUpdate() event, I refresh the adodc control for grid 2:

Private Sub Grid1_AfterUpdate()

' Refresh the link to the totals recordsource
Adodc1.Refresh

end sub


This code does not work correctly. After the second detail record is changed, the first change is made to the totals.
Now if i put a msgbox in the code:

Private Sub Grid1_AfterUpdate()

MsgBox "After Update"

' Refresh the link to the totals recordsource
Adodc1.Refresh

end sub

Then the code will work the way I want it. A record is changed in Grid1, the user moves the cursor to the next record, then the total in Grid2 is updated.

I do not want to have a msgbox after each updated row - how can I get this code to work without the msgbox statement?
I have tried various combinations of refreshing grid2, rebinging grid2 and the like but have not found the answer.
I would appreciate any thoughts, suggestions on the matter.

Thanks!
 
It may be a timing issue - try replacing your msgbox with DoEvents. This will relinquish control to your data update process
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Use a connection object variable, and open the connection to your db, and set both data controls to this connection. Using the same connection may solve the problem.

Option Explicit

Private ConnADO As ADODB.Connection

Private Sub Form_Load()
Set ConnADO = New ADODB.Connection
ConnADO.ConnectionString = XXX
ConnADO.Open

Adodc1.ActiveConnection = ConnADO
Adodc2.ActiveConnection = ConnADO

End Sub

Another, simpler way is this:

Private Sub Form_Load()
Adodc2.ActiveConnection = Adodc1.ActiveConnection
End Sub

This will assure that both Data Controls use the same connection. [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Thank you both for your suggestions. I tried them both and neither one solves the problem. I agree with Johnwm that the problem is probably a timing issue between the update/refresh, I just can't figure out how to solve it!

If you think of any other suggestions, I would greatly appreciate it!



Thanks!

Shannon



Happy Holidays!
 
1. Replace the message box with
Debug.Print "AfterUpdate Fired"
and then see if this text gets printed to the immediate window.

2. Check your Adodc to see whether or not if the values in it are correct, or if it is just the Grid that is not displaying the current data.

Debug.Print Adodc1.Recordset("SomeFieldName")

[/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top