Could anyone help me with ADODB recordset?
Thanks in advance
I have a table, DuplicateSystemEPOS and a query , DuplicateSystemEPOS_INS.
For the query , I did some calculation to count the No_of_Visits and store it in No_Of_INSV column.
Thus, I will get a result in the range of 0 to 3
So what I'm trying to do now is to Update the DuplicateSystemEPOS table AND its column ,INSTITUTION_ACT.
For Example , if the No_Of_INSV is 0, I wanna update the DuplicateSystemEPOS ( INSTITUTION_ACT) column to "P-NHGP".
Both table and query have GROUP_NO as the primary key and the table have duplicate records.
Here are the code that I've been testing out but whenever I run the code below , it does not update anything .
Code:Option Explicit Option Compare Database Private Sub Update_EPOS() 'Initialize variable // Open recordset Dim rsDuplicateEpos As ADODB.Recordset Set rsDuplicateEpos = New ADODB.Recordset 'Connection to the database Dim connector As ADODB.Connection Set connector = CurrentProject.Connection 'adOpenDynamic - type of cursor to know or what is going on with the record set you are working with rsDuplicateEpos.Open "DuplicateSystemEPOS_INS", connector, adOpenDynamic, adLockBatchoptimistic Dim rsDuplicateSystemEPOS As ADODB.Recordset Set rsDuplicateSystemEPOS = New ADODB.Recordset rsDuplicateSystemEPOS.Open "DuplicateSystemEPOS", connector, adOpenDynamic, adLockBatchoptimistic 'Find the target record 'While rsDuplicateEpos.EOF = False Do Until rsDuplicateEpos.EOF 'Check for match If rsDuplicateEpos("No_of_INSV").value = 0 Then If rsDuplicateEpos("GROUP_NO") = rsDuplicateSystemEPOS("GROUP_NO") Then 'rsDuplicateEpos("INSTITUTION_ACT").value = "P-NHGP" 'rsDuplicateEpos.Update 'rsDuplicateSystemEPOS.AddNew rsDuplicateSystemEPOS("INSTITUTION_ACT").value = " P-NHGP" rsDuplicateSystemEPOS.Update End If End If 'exit loop 'rsDuplicateEpos.MoveLast rsDuplicateEpos.MoveNext Loop 'Close variable/ recordset rsDuplicateEpos.Close Set rsDuplicateEpos = Nothing rsDuplicateSystemEPOS.Close Set rsDuplicateSystemEPOS = Nothing End Sub


Reply With Quote


