943,822 Members | Top Members by Rank

Ad:
You are currently viewing page 3 of this multi-page discussion thread; Jump to the first page
Aug 13th, 2008
0

Re: Runtime error in MS-Access

Hi! Came out with the solution just now. plz check out this.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private db As ADODB.Connection
  2. Private rs1 As ADODB.Recordset
  3. Private rs2 As ADODB.Recordset
  4.  
  5. Private Sub Command_Click()
  6. Call fn_DeleteDuplicateRecords("Attribute", "TmpAttribute")
  7. End Sub
  8.  
  9. Public Function fn_DeleteDuplicateRecords(ByVal strTableName As String, ByVal strDupTableName As String)
  10.  
  11. Dim iCatalog As New ADOX.Catalog
  12. Dim i As Integer, j As Integer
  13. Dim strOpen As String
  14.  
  15. On Error GoTo ErrTrap
  16.  
  17. Set db = New ADODB.Connection
  18. Set rs1 = New ADODB.Recordset
  19. Set rs2 = New ADODB.Recordset
  20.  
  21. db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\ProductClass.mdb;Persist Security Info=False"
  22.  
  23. iCatalog.ActiveConnection = db
  24.  
  25. For i = 0 To iCatalog.Tables.Count() - 1
  26. If iCatalog.Tables(i).Name = "NEWTAB" Then 'If table strDupTableName found then
  27. db.Execute "DROP TABLE NEWTAB "
  28. iCatalog.Tables.Refresh
  29. Exit For
  30. End If
  31. Next
  32.  
  33. db.Execute "CREATENEWTAB", , adCmdStoredProc
  34. 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
  35. rs2.Open " SELECT * FROM NEWTAB ", db, adOpenDynamic, adLockOptimistic
  36.  
  37. While Not rs1.EOF
  38. rs2.AddNew
  39. For i = 0 To rs1.Fields.Count - 1
  40. If i = 2 Then
  41. If Len(rs1.Fields(2)) > 255 Then
  42. For j = 1 To Len(rs1.Fields(2)) Step 255
  43. rs2.Fields(i) = rs2.Fields(i) & Mid(rs1.Fields(i), j, 255)
  44. Next
  45. Else
  46. rs2.Fields(i) = rs1.Fields(i)
  47. End If
  48. Else
  49. rs2.Fields(i) = rs1.Fields(i)
  50. End If
  51. Next i
  52. rs2.Update
  53. rs1.MoveNext
  54. Wend
  55.  
  56. If Not rs1 Is Nothing Then
  57. If rs1.State Then rs1.Close
  58. Set rs1 = Nothing
  59. End If
  60. If Not rs2 Is Nothing Then
  61. If rs2.State Then rs2.Close
  62. Set rs2 = Nothing
  63. End If
  64.  
  65. iCatalog.Tables.Refresh
  66. For i = 0 To iCatalog.Tables.Count() - 1
  67. If iCatalog.Tables(i).Name = "NEWTAB" Then 'If table strDupTableName found then
  68. db.Execute "DROP TABLE" & " " & strTableName 'Drop tables original
  69. iCatalog.Tables.Refresh
  70. Exit For
  71. End If
  72. Next
  73.  
  74. 'sometimes Maybe the Execution of the strOpen query is not completed yet.
  75. 'u r trying to delete the original table only after the new table created is found.
  76. 'so the above loop may result in not deleting the original table.
  77. 'Or u try to get help of waiting till the query is executed by the ADO and get a intimation
  78. 'once the query is finished and the new table with distinct records is created.
  79. iCatalog.Tables.Refresh
  80. For i = 0 To iCatalog.Tables.Count() - 1
  81. If iCatalog.Tables(i).Name = "NEWTAB" Then 'If table strDupTableName found then
  82. iCatalog.Tables(i).Name = strTableName 'rename to strTableNamer
  83. iCatalog.Tables.Refresh
  84. Exit For
  85. End If
  86. Next
  87. MsgBox "DELETED DUPLICATE RECORDS SUCCESSFULLY."
  88.  
  89. ErrTrap_Exit:
  90. If Not rs1 Is Nothing Then
  91. If rs1.State Then rs1.Close
  92. Set rs1 = Nothing
  93. End If
  94. If Not rs2 Is Nothing Then
  95. If rs2.State Then rs2.Close
  96. Set rs2 = Nothing
  97. End If
  98. If Not db Is Nothing Then
  99. If db.State Then db.Close
  100. Set db = Nothing
  101. End If
  102. If Not iCatalog Is Nothing Then
  103. Set iCatalog = Nothing
  104. End If
  105. Exit Function
  106.  
  107. ErrTrap:
  108. MsgBox Err.Number & " : " & Err.Description
  109. Resume ErrTrap_Exit
  110.  
  111. End Function
Reputation Points: 26
Solved Threads: 40
Posting Whiz
aktharshaik is offline Offline
316 posts
since Aug 2008
Aug 13th, 2008
0

Re: Runtime error in MS-Access

Is this code working on the database I sent you?.
Reputation Points: 18
Solved Threads: 0
Posting Whiz in Training
dinilkarun is offline Offline
206 posts
since Feb 2008
Aug 13th, 2008
0

Re: Runtime error in MS-Access

No. But i added a query there named CREATENEWTAB

Also check out the field names in your database and the code. i had changed the field names here by appending _Attr to last three fields, because type, value etc may be some keywords or reserved VB words.
Reputation Points: 26
Solved Threads: 40
Posting Whiz
aktharshaik is offline Offline
316 posts
since Aug 2008
Aug 13th, 2008
0

Re: Runtime error in MS-Access

can you send me the database on which the above code is working?
Reputation Points: 18
Solved Threads: 0
Posting Whiz in Training
dinilkarun is offline Offline
206 posts
since Feb 2008
Aug 13th, 2008
1

Re: Runtime error in MS-Access

Check this
Attached Files
File Type: zip ProductClass.zip (39.2 KB, 13 views)
Reputation Points: 26
Solved Threads: 40
Posting Whiz
aktharshaik is offline Offline
316 posts
since Aug 2008
Aug 13th, 2008
0

Re: Runtime error in MS-Access

dude... Its working on the 'Attribute' table. I am now trying to make it work for all the tables(8 of them in total). I will get back to you if I face any difficulties.

Thanks a lot.... Thanks once again.

Regards,
Dinil
Reputation Points: 18
Solved Threads: 0
Posting Whiz in Training
dinilkarun is offline Offline
206 posts
since Feb 2008
Aug 13th, 2008
0

Re: Runtime error in MS-Access

I will get back to you soon
Last edited by dinilkarun; Aug 13th, 2008 at 6:59 am.
Reputation Points: 18
Solved Threads: 0
Posting Whiz in Training
dinilkarun is offline Offline
206 posts
since Feb 2008
Aug 13th, 2008
0

Re: Runtime error in MS-Access

I have now made the code to work for all the tables.....
Thanks a lot dude.....
Keep in touch.....

Thanks once again....

Regards,
Dinil
Reputation Points: 18
Solved Threads: 0
Posting Whiz in Training
dinilkarun is offline Offline
206 posts
since Feb 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: VB6 - MySQL
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: My Program doesnt run, afer installing the setup file. Plz help.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC