Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to find duplicates in recordset using vb6
    primarykey
    data
    text
    <p>Hi i have a recordset name rcdDNE. I read the rtn, accno, first name, Middle name, last name, amount, from text file and store it to the recordset. Now I want to store that values to database table. In my table accno is primary key. So before storing that into my table i want to find out if there is any duplicate accno in my recordset. If i have i want to write it to text file.</p> <p>Can anyone help me.</p> <pre><code>' Set up rcdDNE structure With rcdDNE.Fields .Append "RTN", adVarChar, 9 .Append "AccountNbr", adVarChar, 17 .Append "IndividualName", adVarChar, 22 .Append "FirstName", adVarChar, 50 .Append "MiddleName", adVarChar, 1 .Append "LastName", adVarChar, 50 .Append "Amount", adCurrency End With rcdDNE.Open intFileNbr = FreeFile(1) Open strFileName For Input As #intFileNbr Len = 95 ' Open file for input. Do While Not EOF(intFileNbr) Line Input #intFileNbr, strCurrentLine If Mid(strCurrentLine, 1, 1) = 6 Then strRoutingNbr = Mid(strCurrentLine, 4, 8) strAcct = Trim(Mid(strCurrentLine, 13, 17)) strIndividualName = Trim(Mid(strCurrentLine, 55, 22)) strAmount = Trim(Mid(strCurrentLine, 30, 10)) strAmount = Left(strAmount, Len(strAmount) - 1) curAmount = CCur(strAmount) ' Add new record to temporary recordset With rcdDNE .AddNew .Fields![RTN] = strRoutingNbr .Fields![AccountNbr] = strAcct .Fields![IndividualName] = strIndividualName .Fields![Amount] = curAmount .Update End With End If Loop </code></pre> <p>' Write records to Database</p> <pre><code>frmDNELoad.lblStatus.Caption = "Loading data into database......" Dim lngRecCount As Long lngRecCount = 0 rcdDNE.MoveFirst With cmdCommand .ActiveConnection = objConn .CommandText = "insert into t_DATA_DneFrc (RTN, AccountNbr, FirstName, MiddleName, LastName, Amount) values ('" &amp; rcdDNE("RTN") &amp; "', '" &amp; rcdDNE("AccountNbr") &amp; "', '" &amp; rcdDNE("FirstName") &amp; "', '" &amp; rcdDNE("MiddleName") &amp; "', '" &amp; rcdDNE("LastName") &amp; "', '" &amp; rcdDNE("Amount") &amp; "')" .CommandType = adCmdText End With Set rcddnefrc = New ADODB.Recordset With rcddnefrc .ActiveConnection = objConn .Source = "SELECT * FROM T_DATA_DNEFRC" .CursorType = adOpenDynamic .CursorLocation = adUseClient .LockType = adLockOptimistic .Open End With Do Until rcdDNE.EOF lngRecCount = lngRecCount + 1 frmDNELoad.lblStatus.Caption = "Adding record " &amp; lngRecCount &amp; " of " &amp; rcdDNE.RecordCount &amp; " to database." frmDNELoad.Refresh DoEvents Call CommitNew rcdDNE.MoveNext Loop </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload