Results 1 to 6 of 6
  1. #1
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108

    ADODB looping through and update help!

    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

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    AddNew is to add a new record, not edit existing.

    Saving calculated data is usually not a good idea. Why do you need to save the P-NHGP value? Why not just calculate when needed?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    At first my main table is DuplicateSystem - whereby all the duplicate records are stored ( GROUP NO , LAST VISIT INSTITUTION , LAST VISIT DATE , INSTITUTION TO ACT) .

    So I wanna find how many institutions did the user visit the institution to identify the (INSTITUTION TO ACT)
    I'll use this query
    Code:
    SELECT DISTINCT DuplicateSystem.GROUP_NO, Count(DuplicateSystem.LV_INS) AS NO_OF_INSV
    FROM DuplicateSystem
    GROUP BY DuplicateSystem.GROUP_NO;
    Thus, if the user did not visit any visit , NO_OF_INS =0. Thus, I need to record down in DuplicateSystem ( INSTITUTION TO ACT) that user did not visit any institution ("P-NHGP")

    If the user visited once , NO_OF_INS =1. Thus, I need to record down in
    DuplicateSystem the INSTITUTION TO ACT = LAST VISIT INSTITUTION.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    You are missing my point. Saving this calculated data is not advised and is probably totally unnecessary. Calculate that value when it is needed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    Quote Originally Posted by June7 View Post
    You are missing my point. Saving this calculated data is not advised and is probably totally unnecessary. Calculate that value when it is needed.
    How do you suggest me calculating it ?
    I only know how to use query to calculate.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The query can be included in report RecordSource then expression in textbox:

    =IIf([NO_OF_INSV] = 0, "P-NHGP", Null)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 01-31-2014, 12:09 PM
  2. ADODB Problem
    By albe_ACC in forum Access
    Replies: 7
    Last Post: 10-06-2011, 11:34 AM
  3. ADODB Recrodset (Understanding)
    By danny2000 in forum Access
    Replies: 3
    Last Post: 07-12-2011, 06:00 AM
  4. ADODB Retrieve Value with SQL Help
    By kawi6rr in forum Programming
    Replies: 3
    Last Post: 05-07-2011, 02:03 PM
  5. Adodb
    By sassy in forum Programming
    Replies: 2
    Last Post: 10-26-2009, 06:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums