Solved

DB - Refreshing data in DataGrid

Posted on 2002-03-19
8
163 Views
Last Modified: 2010-05-02
Hello,

I change a certain field in my MS-Access data-base from the program. Then I click on my "Show Query" button. It shows a new form with DataGrid (which is connected to Data-Envirement). However the data I see is old (not updated). Only if I restart the program I see the changes. How can I refresh the query (I thing I should update a command in the Data-Envirement but I don't know how).

Please check your suggestion before sending it.
Once I get a working answer, I will accept it.

Thanks in advance.
   Slava.

--------------------------

If you collect MP3 files, visit my web-page:
http://www.organizermp3.com
0
Comment
Question by:slavikn
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 6880844
Unfortunately, the Refresh method doesn't work when the control's DataSource is a DataEnvironment. Instead, to show the updated recordset changes, first update the DataEnvironment's recordset, then rebind the DataGrid to the DataEnvironment. So, if you have a Refresh button, it's click event might look like this:

DataEnvironment1.rsCommand1.Requery
Set DataGrid1.DataSource = DataEnvironment1

Now, when you click the Refresh button, the code rebinds the DataEnvironment to the DataGrid and refills the control with the refreshed data.
0
 
LVL 15

Accepted Solution

by:
lyonst earned 100 total points
ID: 6880856
does this answer yor question ?

http://www.a1vbcode.com/vbtip.asp?ID=39

The DataGrid control is a great way to display multiple data rows in a table-like format. Unfortunately, the control is also plagued with bugs. Some have been fixed by Service Patch 3, but some haven't. For instance, if you connect the DataGrid to a DataEnvironment, then make changes to the underlying recordset and refresh the DataGrid with the Refresh method, the control still doesn't reflect the changes. Unfortunately, the Refresh method doesn't work when the control's DataSource is a DataEnvironment. Instead, to show the updated recordset changes, first update the DataEnvironment's recordset, then rebind the DataGrid to the DataEnvironment. So, if you have a Refresh button, it's click event might look like this:

DataEnvironment1.rsCommand1.Requery
Set DataGrid1.DataSource = DataEnvironment1

Now, when you click the Refresh button, the code rebinds the DataEnvironment to the DataGrid and refills the control with the refreshed data.

Cheers,

T
0
 
LVL 1

Author Comment

by:slavikn
ID: 6880911
I accepted your answer because of the link. The previous one was the same, but the link is very useful. Thanks.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 15

Expert Comment

by:lyonst
ID: 6882035
Cheers,

bobbit31 - Sorry I didn't see your answer before I posted my comment. I will post some points for you since you also posted the correct answer first.

Cheers,

T.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6882720
hehe, ok :)
0
 
LVL 1

Author Comment

by:slavikn
ID: 6883295
Hi again,

Something strange happens... It worked in a test program, but in the real program I get the following error: "Operation is not allowed when the object is closed."  What is the problem.

Please help!!!
Thanks in advance.

    Slava,
http://www.organizermp3.com
0
 
LVL 9

Expert Comment

by:leechoonhwee
ID: 7778676
I think you closed your recordset.
0
 
LVL 1

Author Comment

by:slavikn
ID: 7785974
leechoonhwee,

I've already accepted an answer before.

Anyway, I used a different way.
ALL my data-operations are performed using DataEnviroment. I don't forget to close recordsets and to reopen them when needed.

Thanks anyway.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question