Duplicate from current record in form

S

STiruchi

Am using a command button (image) and when I click, get the following
message "The expression you entered requires the control to be in the
active window". This previously worked ok and not sure what happened
inbetween or how to rectify.

Thanks in advance for any help.

ST
 
S

STiruchi

Please see code below
__________________________________

Private Sub frm_Activity_DuplicateRecord_Click()
On Error GoTo Err_frm_Activity_DuplicateRecord_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste
Append

Exit_frm_Activity_DuplicateRecord_Click:
Exit Sub

Err_frm_Activity_DuplicateRecord_Click:
MsgBox Err.Description
Resume Exit_frm_Activity_DuplicateRecord_Click

End Sub

_____________________________________
 
B

boblarson

Did you enter the code below? Or did Access do it from a Wizard? That code
has been deprecated and it is just a pain in the butt to try to figure out
what it does. So, I need to ask - what is each line supposed to do? I
haven't used DoMenuItem code in years because the way to do it now is to use
DoCmd.RunCommand acCmdxxxx (where xxxx is the command - in words - so you
actually know what it does).

--
Bob Larson

Free Tutorials and Samples at http://www.btabdevelopment.com

__________________________________
 
L

Linq Adams via AccessMonster.com

That's standard Wizard kludge, Bob:

'Select a record
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
'Copy a record
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70

'Paste a record
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70

and I agree, they should be using

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.GoToRecord , , acNewRec
DoCmd.RunCommand acCmdPaste

This is not a situation where you have a form/subform is it? I think you
might get this message if the the current record was on one and the button to
copy was on the other.
 
S

STiruchi

Sorry, but I am not that conversant with vba coding and so use the
wizard to create the database. Basically I have a form with about 5
fields and all I was trying to do was create a button with a command
to duplicate the current record so that the originator can edit only a
couple of fields.

It is only a single form (although another command button within the
form opens another form).

I guess to provide a solution for me is a hard job.

Thanks for the advise so far.

ST
 
Top