Solved

Do I have to ReQuery after an UpdateBatch in ADO?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MsgBox 2 47
VB6 Compile Compatibility Issue 4 90
Run code from text file in vb 1 56
vb6, excel Run-time error 1004 method 'close' of object 'workbooks' failed 7 44
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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now