Search code examples
vb6foxprodbf

asigning INDEX in DBF from vb6


I have a "users.dbf" table with the "users.cdx" index file it's a free table, so there is no dbc file. Both are located in the same folder. Sometimes when I add a new row in users.dbf, users.cdx is not updated, the link between dbf and cdx is broken. This table belongs to a third party app. To solve this problem I use de command "USE ..\myfolder\users.dbf INDEX ..\myfolder\users.cdx" from a foxpro table viewer and the index file is linked again. Is there any way to use this command from vb6? Thank you


Solution

  • Some code clipped from an old demo:

    CN.Open "Provider=VFPOLEDB.1;Data Source='" _
          & App.Path _
          & "';Mode=ReadWrite|Share Deny None;Deleted=True"
    With CN
        .Execute "ExecScript('USE DemoTable EXCLUSIVE" & vbCr _
               & "INDEX ON CustNumber TAG CustIX" & vbCr _
               & "INDEX ON DELETED() TAG DELETED BINARY')", _
                 , _
                 adCmdText Or adExecuteNoRecords
        'Resume sharing:
        .Execute "ExecScript('USE DemoTable SHARED')", _
                 , _
                 adCmdText Or adExecuteNoRecords
    End With
    

    Point being that you can use ExecScript for such things.