Problems with using command buttons.

Gannett

New member
Local time
Today, 15:57
Joined
Jul 3, 2003
Messages
8
I have been using the command button wizard to make several buttons on my forms.
The navigational buttons work fine but others do not.
When I create a 'duplicate record' command button using the wizard and then try to use it I receive an error message that says.
."The command or action 'paste append' isn't available now"
then when I try to close out of the form it says that I have copied a large amout of data to the clipboard and do I want to save it.

I have created this command in other databases with no problems.

Here is the code:

Private Sub Duplicate_Click()
On Error GoTo Err_Duplicate_Click


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

Exit_Duplicate_Click:
Exit Sub

Err_Duplicate_Click:
MsgBox Err.Description
Resume Exit_Duplicate_Click

End Sub
 
DoMenuItem has been obsolete for years according to Microsoft, change them to the RunCommand equivalent
 
I am only a student and haven't done any VBA coding.
I have only peeked at VBA and don't know how to write it. How do I go about changing the code.
 
I seriously doubt that the answer to this problem is to replace code generated by the MS Wizard. The whole point of using the wizards is to quickly accomplish a task without having to write custom code.

I used the wizard to place a "Duplicate Record" button on a form I'm working on and got the exact same results as Gannett. After thinking about for a minute, I realized that, indeed, Paste Append was not available, for the simple reason that my form DOES NOT have the standard Access Menubar available!

I opened up a db that I keep solely for the purpose of testing out ideas, went to a form that DOES have the standard Access Menubar, and repeated the same steps. This time the duplicate record was indeed created and "Paste Appended" to the table.

Hope this helps.

The Missinglinq
 
Rich is correct that the DoMenuItem code the Wizard creates is obsolete. The wizards DoMenuItem code is not working because the menu bar is not there...thus the DoMenuItem command can not work without the menu bar. Most programmers remove the standard menu bars and tools bars and only use VBA to program their applications.

The following archaic code...

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

Should be replaced with...

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdRecordsGoToNew
DoCmd.RunCommand acCmdPasteAppend

If you were to select the DoMenuItem in your code and press the F1 key you will get this from the Access help files...
In Microsoft Access 97, the DoMenuItem method has been replaced by the RunCommand method. The DoMenuItem method is included in this version of Microsoft Access only for compatibility with previous versions. When you run existing Visual Basic code containing a DoMenuItem method, Microsoft Access will display the appropriate menu or toolbar command for Microsoft Access 97. However, unlike the DoMenuItem action in a macro, a DoMenuItem method in Visual Basic code isn't converted to a RunCommand method when you convert a database created in a previous version of Microsoft Access.

Some commands from previous versions of Microsoft Access aren't available in Microsoft Access 97, and DoMenuItem methods that run these commands will cause an error when they're executed in Visual Basic. You must edit your Visual Basic code to replace or delete occurrences of such DoMenuItem methods.
HTH
 
Thank you for giving me a little insight into why this code is obsolete.

I have tried using the RunCommand code that you gave me Ghudson but I'm just receiving the same error message with "RecordsGoToNew" instead of "Paste Append".
 
Are you able to add new records in your form? I tested the code on a simple Access 97 db before I posted and it worked okay for me. I will detail what each line does for you might have to test each step until you know what is wrong.

'Selects the current record
DoCmd.RunCommand acCmdSelectRecord
'Copies the current record to the clipboard
DoCmd.RunCommand acCmdCopy
'Goes to a new record
DoCmd.RunCommand acCmdRecordsGoToNew
'Pastes the copied record into the new record
DoCmd.RunCommand acCmdPasteAppend

HTH
 
Like Ghudson, I ran the aforementioned code, but in Acccess 2000, and it ran just fine. I suspect, Gannett, that you've got your form property "Allow Additions" set to "No" (it's really easy to do, even accidentally). Go to your form's properties, select "Data" and under "Allow Additions" make sure that "Yes" is selected.

Let us know if this doesn't do it.

The Missinglinq
 
Thanks to everyone who has helped with this problem. I found the answer I was looking for from a co-worker. It was my lack of experience with relational databases that seemed to be the problem. I have a parent table with many child tables linked with a one-to-many relationship. When I was trying to past append it wouldn't let me because I had all tables included in one form.
:D
 

Users who are viewing this thread

Back
Top Bottom