| 416-621-9348 cgreaves@chrisgreaves.com | |
|---|---|
| Home Services Products |
Duplicating an Existing Record
In this lesson we will develop the program code to duplicate the current record of our table; Access VBE will assist us in most of the work.
Create a new Command Button on your form, as before, but this time when the Wizard pops up, choose "Record Operations" from the left-hand pane and choose "Duplicate Record" from the right-hand pane. Elect to use a text caption, and abbreviate the suggested text to "Duplicate" - that's all we need to know about this button. We will call this button "cmd_DuplicateRecord".
When you inspect the generated code you should see this:
Private Sub cmd_Duplicate_Click() On Error GoTo Err_cmd_Duplicate_Click DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70 DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70 DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append Exit_cmd_Duplicate_Click: Exit Sub Err_cmd_Duplicate_Click: MsgBox Err.Description Resume Exit_cmd_Duplicate_Click End Sub
The essential 3 lines are the "DoCmd.DoMenuItem" lines.
If you have placed the "Duplicate" Command Button near your previous "Add" Command Button, now would be a good time to align them (choose Format, Align) and perhaps to make them the same size (Choose Format, Size, Fit To Widest).
Loading
Toronto and Mississauga, Sunday, December 05, 2010 3:20 PM
Copyright © 1996-2010 Chris Greaves. All Rights Reserved.