Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Do I have to ReQuery after an UpdateBatch in ADO?

Posted on 2004-09-14
2
633 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…

808 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