Solved

ADO ReIndex & Error Code

Posted on 2000-03-23
5
333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 143

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 143

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

751 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