Lets see if I can describe this.
It’s easier to do than explain.
I use this technique as a standard in all my databases, protect by a password and usually only access. by the developer for maintenance purposes.
For this workaround, you should understand global fields and know how to define fields.
!!!!Caution!!!!! Deleting records is undoable. Use of this script to delete duplicate records should be run on a copy of your database file. Always keep a backup of your database before performing any scripts that include steps for deletion of records.
1.Create an unique value for each record. i.g. a ClientID field. Some records contain the same identification number, these are the duplicate records you want to find.
If your database doesn’t have a unique identification field, define a calculation field to create one from existing fields. For ex., combine first name, last name, and birthday create a unique identification for each client or person.
2. Add two fields
2.1. a text field, called “Del”, when the script finds a duplicate record, it places an “x” in this field to mark the record.
2.2. a global field, called Global, to store the unique identification while comparing records. Global should be the same data type as the ClientID field.
3.Display the “Del” field.
Create a layout that display the Del field, or add the field to an existing layout. You’ll use this layout to store Find setting in the following step.
4.Store settings. Store Sort and Find settings for the script.
4.1. Sort : in Browse mode, choose Sort from the Mode menu. If fields appear in the Sort Order List, click Clear All. Click ClientID, choose Ascending order, click Move and click Done.
4.2. Find : Choose a layout that displays the Del field. In Find mode, type an X into the Del field and then switch to Browse mode (you don’t have to perform the find request)
5. Define the script, now comes the tricky part
In ScriptMaker, define the Find Duplicates script.
Find all
Sort (Restore, No dialog)
Goto Record – Request – Page (First)
Replace (No dialog, “Del” , “”””)
Set Field (“Global” , “ClientID”)
Loop
Goto Record – Request – Page (Exit after last, Next)
If (“Global = ClientID”)
Set Field (“Del” , “”X””)
Else
Set Field (“Global” , “ClientID”)
End IF
End Loop
Perform Find
When you perform the Find Duplicates script,
1.It finds all records, and then sort them by the ClientID field, so that records with the same ClientID are grouped together.
2.Starting with the first record, the script copies the value from the ClientID field into the Global field.
3. The script goes to the next record and compares the value in ClientID with the value in Global.
3.1. If the values match, the record is a duplicate, the script puts an X in the Del field.
3.2. If the value don’t match, FM copies the ClientID value into Global, and it doesn’t change the Del field.
4. The script repeats step 3 until it reaches the last record in the file.
5. The script finds all records with an X in the Del field, and displays the found set of the duplicate records.
Now delete the duplicate records.
To delete the duplicate records you can manually delete the found set using the Delete All command from the Mode menu after running the script.
This way you can control the deleting of records before making any mistake.
If your script works properly to find the duplicate records, you can add the Delete All command as a last step into the script.
This will automate the whole process.
Hope this will help
Happy FM - John