Solved

ADO ReIndex & Error Code

Posted on 2000-03-23
5
328 Views
Last Modified: 2008-02-01
I have 2 questions, Please answer both of my questions.

1. How to reindex the table using ADO
   for example, I have tableA with fields A, B, C. default index is A, then I want to reindex to B.

2. How to trap error code, so I get the error code and also the error description

FYI, I'm using VB6

  Dewi
0
Comment
Question by:Dewi
5 Comments
 

Expert Comment

by:Dotar_Sojat
ID: 2651996
Not sure how to redindex from code, unsure of why you would want to do this from code...

Trapping errors is easy though:
use On Error goto ErrorHandler

     ---Your code goes here---
Exit Sub (or Function)
ErrorHandler:
msgbox err.code & ":" & err.description,vbexclamation, "An error has occurred!"
End Sub (or Function)

Best thing to do is make your error handler call a sub that writes the name of the sub the error occurred in, the the error description and whatever necessary information needed to try to get a cause of why the error happened.
0
 

Expert Comment

by:FarewellIIArms
ID: 2652445
Hi,

Have a look at the Tables collection of ADOX, the following is extract from Help file.

The following code demonstrates how to create a new foreign key. It assumes two tables (Customers and Orders) exist.

Sub CreateKey()

   Dim kyForeign As New ADOX.Key
   Dim cat As New ADOX.Catalog

   cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=c:\Program Files\Microsoft Office\" & _
      "Office\Samples\Northwind.mdb;"

   kyForeign.Name = "CustOrder"
   kyForeign.Type = adKeyForeign
   kyForeign.RelatedTable = "Customers"
   kyForeign.Columns.Append "CustomerId"
   kyForeign.Columns("CustomerId").RelatedColumn = "CustomerId"
   kyForeign.UpdateRule = adRICascade
   cat.Tables("Orders").Keys.Append kyForeign

End Sub

0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2652464
A) If i understood correctly, you want to change the existing index to use the column B instead of column A. Or is it the primary Key setting you want to change?
What is your database system?

B) Create an ADODB.Connection object, as use that object to assign as ActiveConnection for Commands and Recordsets. If an error occurs, then look at the connection.errors collection


0
 

Author Comment

by:Dewi
ID: 2659589
Hi angelIII,

Yes, exactly, but I want to reindex just for temporaly, not permanent
I'm using MS-SQL 7 and using ADODB object.
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 total points
ID: 2659720
I wonder why you only want the index temporarily.
Whatsoever, the only thing I know is to create a permanent index before your query and to drop it immediately afterwards (making it almost temporary).
I did not verify the whole thing, but the following should work (you can execute multiple statemtent in one execute):
SQL = "CREATE INDEX idx_tmp ON table ( colb)      SELECT * FROM table WHERE colb=4   DROP INDEX table.idx_tmp ")
connection.execute SQL

Hope this helps
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now