For a start, you should not PACK every time you delete a record. This is very inefficient, and it simply doesn't work in a multi-user environment.
You might PACK once a month, or once a week, depending on how many records you typically delete. You can do this at midnight, when no user is using the table.
To hide deleted records, use SET DELETED ON.
Your delete code might look (more or less) like this:
if (user confirms)
if eof()
(Show error message: "There is nothing to delete.")
else
delete
skip
if eof()
go bottom
endif
ThisForm.Refresh()
endif
In this case, you just keep your table open. Closing and re-opening tables is complicated.
Note that SET DELETED is scoped to the current datasession. This means that you have to invoke it in each form. This is best done in your base form (inheritance).
HTH,
Hilmar.
>i have a form that displays employee's firstname and lastname form employee table.
>
>actually this form is a data entry screen for employee leave. (i also have a separate table for leave which is leave.dbf)
>
>the user will enter an employee no., then my form should be able to display the firstname and lastname from employee table.
>
>so i do this in the refresh event of text1 (textbox to display the lastname and firstname of employee)
>
>
>This.Value = alltrim(employee.firstname)+ " " + alltrim(employee.mid) + iif(alltrim(employee.mid)="","",". ") + alltrim(employee.lastname)
>
>
>this code works fine with add and edit buttons except for the delete.
>
>in my delete click event i have this,
>
>
>set multilocks on
>=cursorsetprop("buffering",5,"leave")
>=tableupdate(.t.)
>set multilocks on
>=cursorsetprop("buffering",1,"leave")
>thisform.delete()
>set multilocks on
>=cursorsetprop("buffering",5,"leave")
>=tableupdate(.t.)
>thisform.refresh()
>if eof()
> thisform.text1.visible=.f.
> thisform.txtdesc.visible=.f.
>endif
>
>
>thisform.delete have this code,
>
>
>
>if .not. eof()
> nanswer=messagebox("Are you sure you want to delete?",292,"Program Message")
> do case
> case nanswer=6
> dele
> gfile=juststem(dbf())
>
> use in &gfile
> use &gfile in 0 alias gfile exclusive
> select gfile
> pack
> use
> use &gfile in 0 shared
>
> messagebox("Record deleted!",64,"Program Message")
> endcase
>else
> messagebox("No record to delete!",64,"Program Message")
>endif
>
>
>
>the delete works fine too except that it seems not to refresh text1, which should display the firstname and lastname of the employee.
>
>what should i do? any help pls?
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)