![]() |
|
Published 1999-02-01 Printer-friendly version
I want to allow users to copy an existing record in a list. Is there an easy way to copy a record?
Yes, and you can even copy this code to do it!
I am assuming that you are using the ABC templates (if you arent, you should be). The ABC library is the mechanism that makes this easy.
I am also assuming you are using a BrowseBox control template with the BrowseUpdateButtons control template.
1. First, youll need a local variable in the Browse procedure. This variable is used as a flag to indicate whether or not a record that is being inserted is a copy or a new (blank) record. This should be a BYTE. Lets call it LOC:CopyFlag.

2. Next, the Browse Procedure needs a button that the user will press to copy a record. Populate a button on the WINDOW. Lets call it ?Copy.
3. Double-click on the button to see its embed points.
4. In the EVENT:Accepted for the ?Copy button embed point, add this code:
LOC:CopyFlag = TRUE !Flag as a copy POST(EVENT:Accepted,?Insert) !Press the Insert button

5. In the BRW1.PrimeRecord method (the Embeditor is best for this) add the following code -before- the PARENT.PrimeRecord call:
IF LOC:CopyFlag
SuppressClear = TRUE !Suppress record CLEARing
END

This suppresses clearing of the record buffer so new records appear with the values from the current record.
6. Finally, youll reset the flag. In the BRW1.PrimeRecord method (once again, the Embeditor is best for this) add the following code -after- the PARENT.PrimeRecord call:
LOC:CopyFlag = FALSE !Turn off the copy flag
Thats all there is to it!
Now when a user presses the Copy button, the new record will take on the values from the last current values in all fields, except any auto-number fields. This is exactly what you want, because it respects the integrity of your database design. Good news, huh? Well here is some even better news. This technique works when you are using a form for updates or when you are using edit-in-place. You dont need to change a thing!
I want to display a list in reverse order of the key. I know I could make a descending key, but the data file cannot be converted because it must continue to work with a legacy system. Is there any way to display a list in descending order without a descending key?
Well, you could turn everyones monitor upside down when they are not looking, but then they couldnt read their e-mail. A better way would be to display the list in a custom sort order using a "key-less" browse.
The Additional Sort Fields sets the ORDER for the VIEW. Remember that this is a comma separated list.

I unregistered some of my file drivers in the Database Driver Registry. Now I am trying to add them again. I press the Add button and a file dialog appears, but no files display? Where are my file drivers?
Where, oh, where have my file drivers gone? Oh where, oh where can they be?
The solution is really quite simple. In Windows 95/98/NT, Explorer has a setting allowing you to set the manner in which files display. One of these settings is to Hide System Files. When this is enabled, DLL files do not display. Since database drivers are DLLs, they wont appear.
1. From Windows Explorer, choose View => Folder Options.
2. On the View Tab, check the View All Files box.
3. Your database driver will now appear in the filedialog.

Submit your questions to jim-d@topspeed.com (please mention this column when submitting your questions).
Copyright © 1999-2008 by CoveComm Inc. All Rights Reserved. Reproduction in any form without the express written consent of CoveComm Inc., except as described in the subscription agreement, is prohibited.
Clarion Magazine ISSN 1718-9942
One year: $184
(includes all back issues since '99)
Renewals from $134
Two years: $274
Renewals from $224