Edit Duplicate Records
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Edit Duplicate Records

  1. #1
    Join Date
    Apr 2017
    Posts
    12

    Exclamation Edit Duplicate Records

    Hi guys,

    I am working with a database that contains multiple duplicate records, and my task is to find a way to edit certain fields in these records all at once.

    The relevant
    Code:
    short xyz;
    	  strQry1.Format ( "select * from FrameMsg where MsgIndex = %d",nsMsgIndex);  //Msgindex is used to group them
    	  oDaoRsFrm.Open( dbOpenDynaset, strQry1);
    	
    	  oDaoRsFrm.MoveFirst();
              oDaoRsFrm.MoveLast();
    
    	
    	  xyz = oDaoRsFrm.GetRecordCount();
    
    	  if ( xyz > 0 ) 
    	    {
    	      oDaoRsFrm.Edit();
                  for (short nsLoop1 = 0; nsLoop1 <xyz; nsLoop1++ )
    		  {             	
     
    			 m_EdtMsg.GetWindowText(strName);                                       //This bit in the for loop is just the replacement terms
    			 oDaoRsFrm.SetFieldValue(1,( LPCTSTR )strName);
    
    			 m_CmbWrdCnt.GetWindowText(strName);
    			 oDaoRsFrm.SetFieldValue(5,COleVariant (  ( long ) atoi(strName), VT_I4 ) );
    
    			 m_CmbRT_Tx.GetWindowText(strName);
    			 oDaoRsFrm.SetFieldValue(7,COleVariant (  ( long ) atoi(strName), VT_I4 ) );
    
    			 m_CmbRT_Tx_Sub.GetWindowText(strName);
    			 oDaoRsFrm.SetFieldValue(8,COleVariant (  ( long ) atoi(strName), VT_I4 ) );
    
    			 m_CmbRT_Rx.GetWindowText(strName);
    			 oDaoRsFrm.SetFieldValue(9,COleVariant (  ( long ) atoi(strName), VT_I4 ) );
    
    			 m_CmbRT_Rx_Sub.GetWindowText(strName);
    			 oDaoRsFrm.SetFieldValue(10,COleVariant (  ( long ) atoi(strName), VT_I4 ) );  
                 
    			 
    			 
    			 oDaoRsFrm.MoveNext();
    		 } 
    	  
    	  oDaoRsFrm.Update();
    	  oDaoRsFrm.Close();
    	}
    The MoveNext() was added when I realised that this only updated one record, and adding it gave errors like "No Records Found" or "Update or Cancel Update". I believe it's something to do with the order in which I am manipulating the recordset, but I'm genuinely, sincerely not an expert.

    Please help!!!

  2. #2
    Join Date
    Jan 2009
    Posts
    190

    Re: Edit Duplicate Records

    First, you need an SQL that get you duplicate records, and regarding the result, you edit as you want. More over, after you call oDaoRsFrm.MoveLast() you had tried to call oDaoRsFrm.MoveNext(); ... of course that it wont work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)