| | |
Runtime error in MS-Access
Thread Solved |
Hi! Came out with the solution just now. plz check out this.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private db As ADODB.Connection Private rs1 As ADODB.Recordset Private rs2 As ADODB.Recordset Private Sub Command_Click() Call fn_DeleteDuplicateRecords("Attribute", "TmpAttribute") End Sub Public Function fn_DeleteDuplicateRecords(ByVal strTableName As String, ByVal strDupTableName As String) Dim iCatalog As New ADOX.Catalog Dim i As Integer, j As Integer Dim strOpen As String On Error GoTo ErrTrap Set db = New ADODB.Connection Set rs1 = New ADODB.Recordset Set rs2 = New ADODB.Recordset db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\ProductClass.mdb;Persist Security Info=False" iCatalog.ActiveConnection = db For i = 0 To iCatalog.Tables.Count() - 1 If iCatalog.Tables(i).Name = "NEWTAB" Then 'If table strDupTableName found then db.Execute "DROP TABLE NEWTAB " iCatalog.Tables.Refresh Exit For End If Next db.Execute "CREATENEWTAB", , adCmdStoredProc rs1.Open " SELECT Attribute.ParentUUID, Attribute.Alias_Attr, First(Attribute.Value_Attr) AS FirstOfValue_Attr, Attribute.Type_Attr FROM " & strTableName & " GROUP BY Attribute.ParentUUID, Attribute.Alias_Attr, Attribute.Type_Attr ", db, adOpenKeyset, adLockReadOnly rs2.Open " SELECT * FROM NEWTAB ", db, adOpenDynamic, adLockOptimistic While Not rs1.EOF rs2.AddNew For i = 0 To rs1.Fields.Count - 1 If i = 2 Then If Len(rs1.Fields(2)) > 255 Then For j = 1 To Len(rs1.Fields(2)) Step 255 rs2.Fields(i) = rs2.Fields(i) & Mid(rs1.Fields(i), j, 255) Next Else rs2.Fields(i) = rs1.Fields(i) End If Else rs2.Fields(i) = rs1.Fields(i) End If Next i rs2.Update rs1.MoveNext Wend If Not rs1 Is Nothing Then If rs1.State Then rs1.Close Set rs1 = Nothing End If If Not rs2 Is Nothing Then If rs2.State Then rs2.Close Set rs2 = Nothing End If iCatalog.Tables.Refresh For i = 0 To iCatalog.Tables.Count() - 1 If iCatalog.Tables(i).Name = "NEWTAB" Then 'If table strDupTableName found then db.Execute "DROP TABLE" & " " & strTableName 'Drop tables original iCatalog.Tables.Refresh Exit For End If Next 'sometimes Maybe the Execution of the strOpen query is not completed yet. 'u r trying to delete the original table only after the new table created is found. 'so the above loop may result in not deleting the original table. 'Or u try to get help of waiting till the query is executed by the ADO and get a intimation 'once the query is finished and the new table with distinct records is created. iCatalog.Tables.Refresh For i = 0 To iCatalog.Tables.Count() - 1 If iCatalog.Tables(i).Name = "NEWTAB" Then 'If table strDupTableName found then iCatalog.Tables(i).Name = strTableName 'rename to strTableNamer iCatalog.Tables.Refresh Exit For End If Next MsgBox "DELETED DUPLICATE RECORDS SUCCESSFULLY." ErrTrap_Exit: If Not rs1 Is Nothing Then If rs1.State Then rs1.Close Set rs1 = Nothing End If If Not rs2 Is Nothing Then If rs2.State Then rs2.Close Set rs2 = Nothing End If If Not db Is Nothing Then If db.State Then db.Close Set db = Nothing End If If Not iCatalog Is Nothing Then Set iCatalog = Nothing End If Exit Function ErrTrap: MsgBox Err.Number & " : " & Err.Description Resume ErrTrap_Exit End Function
![]() |
Similar Threads
- Runtime Error - R 6025 - pure virtual function call (Windows NT / 2000 / XP)
- Runtime Error - '-2147217904(800440e10) Help to Correct this (Visual Basic 4 / 5 / 6)
- runtime error 3265 (VB.NET)
- Microsoft VBScript runtime error 800a0005 (ASP)
- segmented error?? (C)
- I get a Runtime Error 424 when trying to access a file in VB (Visual Basic 4 / 5 / 6)
- Windows 2000 server not allowing ASP access. (ASP)
- Runtime Errors (Web Browsers)
- Visual Runtime Error, Sound Problem, Disabled Norton and more! (Windows NT / 2000 / XP)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: VB6 - MySQL
- Next Thread: My Program doesnt run, afer installing the setup file. Plz help.
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





....