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
.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & gsAccessPath & "\Americraft.mdb"
.CursorLocation = adUseClient
Set rsFg = New ADODB.Recordset
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"
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:
.Filter = "ITEM='" & txtFields(0) & "' AND CUSTPO='" & txtFields(1) & "'"
!onhand = !onhand - Val(txtFields(3))
!ctnsonhand = !ctnsonhand - Val(txtFields(3))
.Filter = ""
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?