ITableSort Sort method in VBA

571
2
02-22-2011 09:16 AM
KyungKim
New Contributor
Hi,

Using my VBA codes, I was trying to sort an attribute table based on two fields, but the ArcMap stopped working immediately after the codes were run.  Actualy, the codes were composed based on sample codes to the best of my guess; particularly, I don't understand why "Nothing" is put there on the last line.  Would someone please explain about it and how to complete the macro for it to run well?

   -----
   -----

    Dim pTableSort As ITableSort
    Set pTableSort = New esriGeoDatabase.TableSort
   
    Dim pTable As ITable
    Set pTable = pTableProperty.Table
   
    Set pTableSort.Table = pTable
    pTableSort.Fields = "OBJECT_ID, UFI"
    pTableSort.Ascending("OBJECT_ID") = True
    pTableSort.Ascending("UFI") = True
           
    pTableSort.Sort Nothing

    ----
    ----

Thank you!

Kyung
0 Kudos
2 Replies
JamesCrandall
MVP Frequent Contributor
I don't understand why "Nothing" is put there on the last line.  Would someone please explain about it and how to complete the macro for it to run well?


Not totally sure, but I believe that the ITable.Sort method accepts a parameter of ITrackCancel, which is why you just specify "Nothing" on:

pTableSort.Sort Nothing

I don't think it should affect your success or not and I am usure of why you are getting the behavior you seem to be experiencing.  What version of ArcGIS are you running?  Unless I am missing something obvious, I don't necessarily think anything is wrong with your code.  Anyway, here is exact code sample from the EDN site:

http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriGeoDatabase/ITableSort.htm
0 Kudos
KyungKim
New Contributor
Not totally sure, but I believe that the ITable.Sort method accepts a parameter of ITrackCancel, which is why you just specify "Nothing" on:

pTableSort.Sort Nothing

I don't think it should affect your success or not and I am usure of why you are getting the behavior you seem to be experiencing.  What version of ArcGIS are you running?  Unless I am missing something obvious, I don't necessarily think anything is wrong with your code.  Anyway, here is exact code sample from the EDN site:

http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriGeoDatabase/ITableSort.htm


Woud you please explain what ITrackCancel parameter is about?  I am using ArcGIS 9.2.  My code was modeling the same code sample.  Before trying this macro, I had more sever problem with the following macro:

Dim pTable As ITable
Set pTable = pTableProperty.table

Dim pTableSort As ITableSort
Set pTableSort = New tableSort

Set pTableSort.table = pTable
pTablesort.Fields = "OBJECT_ID, UFI"
pTableSort.Sort

The queer thing is, in this case, when I typed pTableProperty.Table, it automatically changed to pTableProperty.table (with small t), and also New TableSort changed to New tableSort (with small t), and also pTableSort.Table changed to pTableSort.table (small t).  Do you know why is it?  Anyhow, with this macro, when run, it gave me a big problem, about which I had put up the following thread in the forum.


(Quote)

I added a few code lines of macro in ArcGIS VBA Editor and tried to run it, but a Compile error: Argument not optional window appeared. I clicked OK button or close button on the window, but the window didn't close. Now, when I try to close the VBA Editor window itself, it will not close either. I was stuck with it, I could not close the ArcMap. To get out of it, I had to turn off my computer. After that, when I tried to open up the .mxd file again, the ArcMap just shows the VBA Editor again with the same Compile error window which as before will not be closed with the click of OK button or close button. How can I close the editior and access all the codes that I have been working on? The .mxd file has many macros that I have created. How can I access them? I am in a dire situation! Could someone help me out? I would appreciate your help!!

Thanks.

Kyung

(Unquote)

I am attaching here the error message window that appeared as mentioned in the thread for your reference. 

After this thread, I could find the previous version of the .mxd file and I could continue to make the macro, and put up a thread to which you replied... Could all these background ring a bell to you?  I hope so.

Kyung
0 Kudos