VBA tie to copy/paste

  • Thread starter Thread starter Leif
  • Start date Start date
L

Leif

I would like to be able to tie, via VBA, into a copy/paste
operation. Specifically, I would like to clear a field
after the paste of a record (several fields) of
information. This is a date field, and if the user
forgets to change it, he will put data in for the wrong
date.

I was thinking of the keypress event, looking for a
Control-V, but what if the user uses paste from the menu?
Is there a more generic way to handle this situtation?

Thanks,
Leif
 
Leif said:
I would like to be able to tie, via VBA, into a copy/paste
operation. Specifically, I would like to clear a field
after the paste of a record (several fields) of
information. This is a date field, and if the user
forgets to change it, he will put data in for the wrong
date.

I was thinking of the keypress event, looking for a
Control-V, but what if the user uses paste from the menu?
Is there a more generic way to handle this situtation?


Copy/Paste is a user interface feature that is often
inappropriate in a running application. When you're trying
to duplicate most(?) of a record, Copy suffers from only
being able to copy the visible controls and, as you've
found, it copies all the visible controls.

A far more controllable, but a little more tedious,
technique is to copy the desired fields individually.

With Me.RecordsetClone
.AddNew
!fieldx = Me.fieldx
!fieldy = Me.fieldy
. . .
!fieldz = Me.fieldz
!fielda = Date
. . .
!fieldc = 123
.Update
Me.Bookmark = .LastModified
End With

This approach allows you to copy only the fields you want to
copy, skip copying any fields you don't want to copy and set
specific values when that's what you want.
 
Marsh,

Thanks for your reply. In this particular case I only
need to copy visible controls. To set up a menu or
buttons for copy/paste is possbile, using your logic.
However, asking users to give up Ctrl-C / Ctrl-V is
swimming up stream. Besides, offering an alternative will
still allow them to bypass it with Ctrl-C / Ctrl-V.

I've tried using the keypress event for the form, with the
key Preview set to Yes. Seems to work great for
everything BUT Ctrl-C & Ctrl-V. So, I'm guessing
something lower level (i.e., Windows call) is necessary.
If I could intercept the Ctrl-C and Ctrl-V I could use
your logic to do the job. Is there a way to do this?

Regards,
Leif
 
Marsh,

Thanks for your reply. In this particular case I only
need to copy visible controls. To set up a menu or
buttons for copy/paste is possbile, using your logic.
However, asking users to give up Ctrl-C / Ctrl-V is
swimming up stream. Besides, offering an alternative will
still allow them to bypass it with Ctrl-C / Ctrl-V.

I've tried using the keypress event for the form, with the
key Preview set to Yes. Seems to work great for
everything BUT Ctrl-C & Ctrl-V. So, I'm guessing
something lower level (i.e., Windows call) is necessary.
If I could intercept the Ctrl-C and Ctrl-V I could use
your logic to do the job. Is there a way to do this?


There probably is some way using some window's system
hooks, APIs, and I don't know what else, but I'm not the one
to get into that kind of thing. Sorry.
--
Marsh
MVP [MS Access]



 
Back
Top