Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ADO ReIndex & Error Code

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
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…
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…
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…
Suggested Courses

972 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