Solved

ADO ReIndex & Error Code

Posted on 2000-03-23
5
327 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

10 Experts available now in Live!

Get 1:1 Help Now