Solved

Do I have to ReQuery after an UpdateBatch in ADO?

Posted on 2004-09-14
2
621 Views
Last Modified: 2013-12-25
I'm using Visual Basic 6 and ADO to open MS Access tables. Here is a sample of my code to create a connection and open a table:

Dim cn As ADODB.Connection, rsFg As ADODB.Recordset
Set cn = New ADODB.Connection
With cn
.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & gsAccessPath & "\Americraft.mdb"
.CursorLocation = adUseClient
.Open
End With

Set rsFg = New ADODB.Recordset
With rsFg
Set .ActiveConnection = cn
.CursorLocation = adUseClient .CursorType = adOpenDynamic
.LockType = adLockBatchOptimistic
.Source = "SELECT KEY,CUSTNO,ITEM,CUSTPO,ONHAND,CTNSONHAND,MATERIAL,DLABOR,VAR_OH,FIXED_OH FROM FG ORDER BY ITEM, CUSTPO"
.Open
End With


My table has an autonumber field named KEY as its primary key. Below is a sample of the code I use to update the table:

With rsFg
.Filter = "ITEM='" & txtFields(0) & "' AND CUSTPO='" & txtFields(1) & "'"
!onhand = !onhand - Val(txtFields(3))
!ctnsonhand = !ctnsonhand - Val(txtFields(3))
.UpdateBatch
.Filter = ""
.Requery
 End With

Is it important to include the primary key in the fields I get in my 'SELECT' statement, i.e. will the primary key field help ADO to find the right record to update? Do I have to issue a Requery after each UpdateBatch in order to make sure that ADO will find the right record to update the next time I do an UpdateBatch? Can I just Update instead of UpdateBatch?
0
Comment
Question by:BruceHSanford
2 Comments
 
LVL 13

Accepted Solution

by:
Michael_D earned 125 total points
ID: 12060389
You should use .UpdateBatch only if you changing several records without updating each one separatly.
You don't have to "help" ADO doing its job :)
This mean that you don't have to include "KEY" field into Select if you don't need it .
.Requery method ensure that you have "last updated" data - usefull only if your data might be changed from other application or workstation. All changes that YOU made already in your recordset.
0
 
LVL 10

Expert Comment

by:anv
ID: 12062469
yes u can use update instead of updatebatch in ur case..

since ur Recordset's cursortype is adOpenDynamic so the changes will be reflected to u instatntly... as and when data changes in that table...
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

786 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