PACK command in FoxPro 2.x

10-26-2004, 08: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
If rsObjectRS.EOF = False Then
.Delete adAffectCurrent
End If
' * * 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.Mode = adModeReadWrite
dbObjectDB.Open "Provider=VFPOLEDB.1;Data Source=" & App.Path & ";Mode=ReadWrite|Share Deny" _
& " None;Collating Sequence=MACHINE"
.ActiveConnection = dbObjectDB
.Source = "PACK Customer"
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.CursorLocation = adUseClient
End With

10-26-2004, 08: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.Execute "Set Exclusive On", adCmdText
cnFox.Execute "Delete from contract", adCmdText
cnFox.Execute "Pack", adCmdText

Set cnFox=Nothing

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

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum