Solved

Failure to Save new data in first record

Posted on 2004-04-22
6
304 Views
Last Modified: 2010-05-02
Hi......
My VB application uses a data control to connect to an Access table.... I use a combo box to navigate between the  table's records without a problem.

When I change the  data in the textboxes which are bound to a record in the table the new data gets saved  and replaces the old data as soon as I move the recordset by selecting another recrord from the combo box... the only exception to this is the top record in the combo box...... when new data is entered in that first record and I move to a different record I find the textboxes revert  back to their origninal value, refusing to update the changes.... every other record upadate  the changes  but not the first recrod.

Here is the combo box click event code:

rs.MoveFirst
Do Until Combo1.Text = Me.Text1.Text
If Not rs.EOF Then rs.MoveNext
Loop

I noticed the following: When data is changed in the top record and I select another record from the combo box, the combo box doesn't respond the first time.... it doesn't move the recordset until I click a second time.... please help if you can.
 
0
Comment
Question by:tariqanis
  • 2
  • 2
  • 2
6 Comments
 
LVL 11

Expert Comment

by:jmwheeler
ID: 10889368
try this

rs.UpdateRecord
0
 
LVL 4

Accepted Solution

by:
Javin007 earned 250 total points
ID: 10889422
Unfortunately, data bound controls are VERY VERY buggy in Visual Basic.  It's possible you've got a coding problem, but equally as possible that you've found one of the many bugs.

For database work, it's always best to go with ADODB.  It's also incredibly simple, and gives you the most flexibility.

ADODB basically has just two objects that you need:

ADODB.Connection
ADODB.Recordset

So you would first go to your project references, and add the "Microsoft ActiveX Data Objects 2.X Library"

Then, you have to build your "connection" to the database, which will require a connection string.  The easiest way to do this is to ALSO add an ADODC control to your form temporarily, use it to make a connection to your database, and then just copy the connection string it creates, and remove the control.  (More on connection strings can be found here: http://www.able-consulting.com/MDAC/ADO/Connection/OLEDB_Providers.htm#OLEDBProviderForMicrosoftJet)

'So now you've got you're connection string, something like this:

strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=c:\somepath\myDb.mdb;" & _
           "User Id=admin;" & _
           "Password="

'You create your connection object:

Set conMyDatabase = New ADODB.Connection

'And a recordset.

Set rcdRecordset = New ADODB.Recordset

'Open the connection to the database.

conMyDatabase.Open strConnect

'Use the connection to open a recordset from the database:

rcdRecordset.Open "SELECT * FROM Table", conMyDatabase

(There are a large number of options here that would require a small amount of reading to understand.  But not too complex.)

Now, just create a REGULAR combobox, and when it's time to update the items in the combobox, you can simply use:

rcdRecordset.MoveFirst
cmbBox.Clear
While Not rcdRecordset.EOF
   cmbBox.AddItem rcdRecordset("FieldName).Value
Wend

If ya learn to do things a little lower level like this, believe me, it will save you MONTHS worth of bug chasing with data bound controls.

-Javin
0
 
LVL 11

Expert Comment

by:jmwheeler
ID: 10892112
I would agree with Javin.  If your going to make any kind of respectable program accessing a database from VB, ADODB is the way to go.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:tariqanis
ID: 10892484
Hi Javin

I am trying it your way.....  the code you gave for filling the combobox is fine but now I am at the stage where I need to use the  combobox to move between  records...... I tried using the following code  but the application hung - here is the code  

rsTracking.MoveFirst
Do Until Combo1.Text =  AC_No.text
If Not rsTracking.EOF Then
rsTracking.MoveNext
End If
Loop

I used the above code to select the record I want to move to... AC_No is the textbox that contains the ID for each record in the recordset I am browsing...... but like I said the application hangs each time I select a record from the Combobox...
0
 
LVL 4

Expert Comment

by:Javin007
ID: 10894404
Hrm.  If it's hanging in that loop, you need to check Combo1.Text and make SURE it matches AC_No.text at some point.  Otherwise, once it gets through all the records in the database and doesn't have an exact match, it'll just bounce back and forth between the Do/Loop.

-Javin
0
 

Author Comment

by:tariqanis
ID: 10896245
Thank you Javin for all your help.... you did get me to switch.... BUT.. the switch is not as easy as you make it out.... I had to learn a lot of other things on the way... like how to Load every field in the database into the textboxes just to geth them displayed  on the form (done automatically by the data control once you bind it to your record source) and when to do it (almost every time you move from record to record), then how commit the updated data back into the database (again some thing the data control makes easy) and other detailes which I struggled since I took up your advise... but I think I'll be well rewarded for the effort... so Thanks again...

The problem in this last case was, like you said, a problem with my recordset.... empty date fields in the table... now it's working fine....
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

809 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