472,993 Members | 3,218 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 software developers and data experts.

DoCmd.DoMenuItem copy and paste

121 100+
Hi I have a main form that holds records for scheduled meetings, date time location etc... in that form i have a sub form that has a list of equipment resources that you can assign to the meeting in the main form. I have two buttons in the sub form one for selecting and copying all the records and another for pasting the records this enables me to copy and paste the equipment resources from one scheduled meeting to another.

The buttons are coded as follows

Select and copy:-


Expand|Select|Wrap|Line Numbers
  1. DoCmd.DoMenuItem acFormBar, acEditMenu, acSelectAllRecords, , acMenuVer70
Expand|Select|Wrap|Line Numbers
  1. DoCmd.DoMenuItem acFormBar, acEditMenu, acCopy, , acMenuVer70

Paste:


Expand|Select|Wrap|Line Numbers
  1.     DoCmd.GoToRecord , , acNewRec
Expand|Select|Wrap|Line Numbers
  1. DoCmd.DoMenuItem acFormBar, acEditMenu, acSelectRecord, , acMenuVer70
Expand|Select|Wrap|Line Numbers
  1. DoCmd.DoMenuItem acFormBar, acEditMenu, acPaste, , acMenuVer70

This all works fine if i follow these steps.
1: open form
2:locate meeting 1
3:copy equipment from meeting 1
4: locate meeting 2
5:paste equipment from meeting1 to meeting 2


it will not work if i edit meeting 2 first ie. if i take the following steps
1:open form
2:locate meeting 2
3:delete equipment record from list
4:locate meeting 1
5:copy equipment from meeting1
6:locate meeting 2
7:paste equipment from meeting1 to meeting 2


when the records have been pasted using the first example the MS Access message box "you are about to paste 2 records ok cancel" appears

when the second example is used the MS Access message box "you are about to paste 2 records ok cancel" does not appear
and if you look at the table behind the forms it has not updated even though it looks like the new records have been added in the form.

if i do not use the buttons and do the tasks "manualy" either using the copy and paste icons on the toolbar or use the edit copy and paste menu

or if i use short cut keys ctrl c and ctrl v

it works fine which is why i think that it may be related to the butons.

This is the sql statement in the subform

Expand|Select|Wrap|Line Numbers
  1. SELECT T_EquipBookTemp.EquipBookTmpID, T_EquipBookTemp.EquipID, T_EquipBookTemp.StartTimeID, T_EquipBookTemp.EndTimeID, T_EquipBookTemp.SessionID, T_EquipBookTemp.EquipBooked, T_ActiveSession.StartDate, T_ActiveSession.EndDate, T_ActiveSession.StartTime, T_ActiveSession.EndTime, T_EquipBookTemp.box09, T_EquipBookTemp.EquipBooked
i also have cascade update and cascade delete applied in the relationship between the two tables

Please help

Regards Phill
Aug 31 '08 #1
5 10977
nico5038
3,080 Expert 2GB
I must warn you for using the "DoCmd.DoMenuItem" command.
When the user does click on the form of another application the execution will fail... :-(

For the general "move" problem I created in the past a sample database to show how to move items in a list and in a subform. Both "Up/Down" to create a user defined sequence and "Left/Right" for filling a selection like Access does in several wizards with [<] and [>} buttons.

Just checkout the attached sample.

Nic;o)
Attached Files
File Type: zip Sample-Listbox-Datasheet-Up-Down-LeftRight2000.zip (57.0 KB, 553 views)
Aug 31 '08 #2
phill86
121 100+
hi nico,

thanks for the reply i dont understand why it works fine if i do not edit the record first or if i edit the record then close and reopen the form and then paste it also works fine it seems to be that it is not updating the underlying table for some reason is there any way to reload the form before i paste the records?

Cheers Phill
Aug 31 '08 #3
nico5038
3,080 Expert 2GB
Hi Phill,

The data on the form will be in a "pre update" status. When moving to another record the BeforeUpdate event will be triggered and then the data will be saved in the database.
You can "force" this save of the record by issuing a save command like:
DoCmd.RunCommand acCmdSaveRecord

As you see this is no "DoMenuItem" command and all "DoMenuItem" commands can best be "translated" into "RunCommand" statements.

Nic;o)
Aug 31 '08 #4
phill86
121 100+
Hi nico,

thanx for the reply that still did not work i have changed all the code on the buttons to runcommands and for some reason the records do not get pasted in the table if the records have been edited previously the second time you try and paste the records you do not get the ms access mesaage box that says "you are about to paste 2 records ok cancel" so this points to something that is happening in the table or query if you paste it manually ie ctrl v or via the edit menu it works please help

thanks phill

Hi Phill,

The data on the form will be in a "pre update" status. When moving to another record the BeforeUpdate event will be triggered and then the data will be saved in the database.
You can "force" this save of the record by issuing a save command like:
DoCmd.RunCommand acCmdSaveRecord

As you see this is no "DoMenuItem" command and all "DoMenuItem" commands can best be "translated" into "RunCommand" statements.

Nic;o)
Sep 1 '08 #5
nico5038
3,080 Expert 2GB
I think your delete combined with the cascading links is causing this "trouble"

So I guess we need a new approach to handle the move.Obviously you want to move single and multiple records from one "main" to another "main" table.
This can be achieved in multiple ways. For my left/right move I use a Yes/No field for the selection and that's also an option for you.
The other approach would be to handle the matter from a multi select listbox, although the coding will be harder in this manner.

To start it might be a good thing you attach a sample .mdb to your next comment (write your reply and after saving follow the "edit" link at the bottom to manage an attachment).

Nic;o)
Sep 1 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: (Pete Cresswell) | last post by:
I've got this DoCmd in a fields Change() event so that as the user types, the underlying table (also visible in another screen...) will be updated in realtime - instead of waiting for the screen TB...
6
by: Squirrel | last post by:
I have a command button on a subform to delete a record. The only statement in the subroutine is: DoCmd.RunCommand acCmdDeleteRecord The subform's recordsource is "select * from tblVisit order...
4
by: WJA | last post by:
I'm probably missing something here but I can't understand the following. When 2 users try to save a record with the same primary key (a number field), the first record saves as expected, but the...
2
by: deko | last post by:
I'm trying to expand a popup form and make additional controls available by making the form footer visible and resizing the form. This works: Me.FormFooter.Visible = Me!tglAdvanced.Value...
4
by: Legendary Pansy | last post by:
I was checking out the 101 C# Samples, specifically Windows Forms - Use the Clipboard. I took a look at the code for a while, and I understand what the program is doing with the cut, copy, pasting...
7
by: lgbjr | last post by:
Hello All, Im using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
17
by: Steve | last post by:
I'm trying to code cut, copy, and paste in vb 2005 so that when the user clicks on a toolbar button, the cut/copy/paste will work with whatever textbox the cursor is current located in (I have...
3
by: cm5th | last post by:
I understand Access lets the VBA statements following a DoCmd statement execute before a DoCmd has completed. I have a situation where I use a DoCmd.DoMenuItem (copied from the UNDO button VBA) to...
4
by: gazza10001 | last post by:
Hi i hope you can help my company uses access and has modified for its needs usually what happens is you serach for the invoice by its number and then it brings all the information up such as...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.