Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > Updating/displaying MSHFlexGrid


Reply
 
Thread Tools Display Modes
  #1  
Old 04-19-2005, 11:55 PM
phillg11 phillg11 is offline
Newcomer
 
Join Date: Apr 2005
Posts: 7
Question Updating/displaying MSHFlexGrid


Hi,
I have an annoying problem. In a nutshell I have a small database program in which I add data to an existing (Access) database, on clicking a command button the data is added, the form is closed and a second form is shown which displays the data in an MSHFlexGrid. Here’s the problem, when the second form is displayed the MSHFlexGrid doesn’t show the just added data. If I insert a break point between closing the first and opening the second forms it works fine and if I manually open the database the updated data is present. I have tried various combinations of refresh/update etc but have had no result.

Code below

Thanks for any help,
Phill
Code:
...................................................... Dim conn As ADODB.Connection __________________________________________ Private Sub cmdAddData_Click() Dim recAddClient As ADODB.Recordset Set conn = New ADODB.Connection conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\db1.mdb" conn.Open Set recAddClient = New ADODB.Recordset recAddClient.Open "select * from table1", conn, adOpenDynamic, adLockOptimistic, adCmdText With recAddClient .AddNew .Fields("title").Value = cmbTitle.Text .Fields("FirstName").Value = txtFields(0).Text .Fields("surname").Value = txtFields(1).Text .Fields("ClientID").Value = txtClientID.Text .Update End With Unload Me frmPatientSearch.Show End Sub ...................................................... Dim conn As ADODB.Connection __________________________________________ Private Sub Form_Load() Dim recPopGrid As ADODB.Recordset Set conn = New ADODB.Connection conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\db1.mdb" conn.Open Set recPopGrid = New ADODB.Recordset recPopGrid.CursorLocation = adUseClient recPopGrid.Open "select * from table1", conn, adOpenDynamic, adLockOptimistic, adCmdText Set MSHFlexGrid1.DataSource = recPopGrid End Sub

Last edited by Shurik12; 04-21-2005 at 01:09 AM.
Reply With Quote
  #2  
Old 04-20-2005, 02:22 AM
Shurik12 Shurik12 is offline
Steppe Walker

Retired Moderator
* Expert *
 
Join Date: Jul 2002
Location: Ukraine/Russia/Belgium
Posts: 7,227
Default

Hi,

Every time you update the underlying recordset you have to rebind it

Code:
.... Set MSHFlexGrid1.DataSource = Nothing Set MSHFlexGrid1.DataSource = recPopGrid ....
__________________
"A diaper is not like a computer that makes satisfying burbling noises from time to time, hinting at great inner complexity." Malcolm Gladwell

"I'm sitting here completely surrounded by no beer." Onslow, 'Keeping up appearances'
Reply With Quote
  #3  
Old 04-20-2005, 08:30 PM
phillg11 phillg11 is offline
Newcomer
 
Join Date: Apr 2005
Posts: 7
Default

Shurik12, thanks for the reply, but I'm still struggling. I have further simplified the example putting it on one form with MSHFlexGrid1, one text box and one command button. I added the code you suggested, but I must be missing something. Could you check what I have below.

Thanks,
Phill

Code:
Dim conn As ADODB.Connection Dim recPopGrid As ADODB.Recordset Dim recAddClient As ADODB.Recordset ____________________________________________ Private Sub Command1_Click() Set conn = New ADODB.Connection conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\db1.mdb" conn.Open Set recAddClient = New ADODB.Recordset recAddClient.Open "select * from table1", conn, adOpenDynamic, adLockOptimistic, adCmdText With recAddClient .AddNew .Fields("title").Value = Text1.Text .Update End With Set MSHFlexGrid1.DataSource = Nothing Set MSHFlexGrid1.DataSource = recPopGrid MSHFlexGrid1.Refresh End Sub ____________________________________________ Private Sub Form_Load() Set conn = New ADODB.Connection conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\db1.mdb" conn.Open Set recPopGrid = New ADODB.Recordset recPopGrid.CursorLocation = adUseClient recPopGrid.Open "select * from table1", conn, adOpenDynamic, adLockOptimistic, adCmdText Set MSHFlexGrid1.DataSource = recPopGrid End Sub

Last edited by Shurik12; 04-21-2005 at 01:08 AM. Reason: please use vb-tags
Reply With Quote
  #4  
Old 04-21-2005, 01:19 AM
Shurik12 Shurik12 is offline
Steppe Walker

Retired Moderator
* Expert *
 
Join Date: Jul 2002
Location: Ukraine/Russia/Belgium
Posts: 7,227
Default

Let's go back to your original example and try the following

Code:
__________________________________________ Private Sub cmdAddData_Click() Dim recAddClient As ADODB.Recordset Dim conn As ADODB.Connection Set conn = New ADODB.Connection Set recAddClient = New ADODB.Recordset conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\db1.mdb" conn.Open recAddClient.Open "select * from table1", conn, adOpenKeySet, adLockOptimistic, adCmdText With recAddClient .AddNew .Fields("title").Value = cmbTitle.Text .Fields("FirstName").Value = txtFields(0).Text .Fields("surname").Value = txtFields(1).Text .Fields("ClientID").Value = txtClientID.Text .Update End With DoEvents Set recAddClient=Nothing Set conn=Nothing Unload Me frmPatientSearch.Show End Sub ...................................................... __________________________________________ Private Sub Form_Load() Dim conn As ADODB.Connection Dim recPopGrid As ADODB.Recordset Set conn = New ADODB.Connection Set recPopGrid = New ADODB.Recordset conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\db1.mdb" conn.Open recPopGrid.CursorLocation = adUseClient recPopGrid.Open "select * from table1", conn, adOpenKeySet, adLockOptimistic, adCmdText Set MSHFlexGrid1.DataSource = recPopGrid ..... End Sub

Regards,
Shurik.
__________________
"A diaper is not like a computer that makes satisfying burbling noises from time to time, hinting at great inner complexity." Malcolm Gladwell

"I'm sitting here completely surrounded by no beer." Onslow, 'Keeping up appearances'

Last edited by Shurik12; 04-21-2005 at 01:26 AM.
Reply With Quote
  #5  
Old 04-25-2005, 11:22 PM
phillg11 phillg11 is offline
Newcomer
 
Join Date: Apr 2005
Posts: 7
Default

Thanks, it feels good to stop hitting my head agaianst that wall
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->