PACK command in FoxPro 2.x

rjm
10-26-2004, 09:02 AM
In foxpro, deleting a record does not physically delete the record, it just flags it for deletion. In order to physically remove the record(s), I have to issue the PACK command but I am having problems with it.

Does anyone know the proper way to issue this command?

Thanks in advance for any help.


' Code
With rsObjectRS
'-- Delete all records from Customer table
.ActiveConnection = dbObjectDB
.Source = "SELECT * FROM Customer WHERE CustomerID = " & cCustomer.CustomerID
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.CursorLocation = adUseClient
.Open
If rsObjectRS.EOF = False Then
.Delete adAffectCurrent
End If
.Close
dbObjectDB.CommitTrans
' * * My records are flagged for deletion up to here, but not yet removed
' How do you issue the PACK command from this point on?
dbObjectDB.Close
dbObjectDB.Mode = adModeReadWrite
dbObjectDB.Open "Provider=VFPOLEDB.1;Data Source=" & App.Path & ";Mode=ReadWrite|Share Deny" _
& " None;Collating Sequence=MACHINE"
dbObjectDB.BeginTrans
.ActiveConnection = dbObjectDB
.Source = "PACK Customer"
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.CursorLocation = adUseClient
.Open
dbObjectDB.CommitTrans
End With

Flyguy
10-26-2004, 09:53 AM
Have you tried the .Execute method of the connection object?

Based on some sample on the net:

Dim cnFox As ADODB.Connection

Set cnFox = New ADODB.Connection
cnFox.Provider = "MSDASQL.1"
cnFox.Properties("Data Source").Value = "fox"

cnFox.Open

cnFox.Execute "Set Exclusive On", adCmdText
cnFox.Execute "Delete from contract", adCmdText
cnFox.Execute "Pack", adCmdText

cnFox.close
Set cnFox=Nothing

rjm
10-26-2004, 10:23 AM
Thanks, that worked!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum