Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ADO ReIndex & Error Code

Posted on 2000-03-23
5
Medium Priority
?
340 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 400 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

Industry Leaders: 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Suggested Courses

670 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