I work for a custom cabinetry manufacturer and we write our own pricing program for our product. I have a form that has a pop-up box so the user can select which side the hinge will be on for ambiguous doors on that cabinet. I've got that to work so far, but when they copy an item and paste it at the bottom I don't want the pop-up box to come up. Is there any way in Access VBA to know whether the new record is being pasted or entered manually?
It sounds like you may need to rethink your interface. Can you provide more info. on what you want to happen?
We are using the AfterUpdate event on the textbox that they enter the name of the item in. I want the form to use the information pasted to fill out the record and bypass the pop-up box.
Perhaps something on the lines of this would suit.
Option Compare Database
Public gvarPasted As Boolean
Private Sub txtText_AfterUpdate()
If Not gvarPasted Then
'Open pop-up here
Else
gvarPasted = False
End If
End Sub
Private Sub txtText_KeyDown(KeyCode As Integer, Shift As Integer)
'Detect ctrl-V combination
If Shift = acCtrlMask And KeyCode = vbKeyV Then
gvarPasted = True
End If
End Sub
That code works if they actually press [ctrl]+V to paste. If they right click and paste it still shows the message box. Any ideas how to prevent this?
You can customize the menu, for example if you add code like so to a standard module:
Public gvarPasted As Boolean
Function AssignVar()
gvarPasted = True
DoCmd.RunCommand acCmdPaste
End Function
You can set the Action property of Paste on the menu to this function using the customize option of the toolbar menu. You will also need to create your own shortcut menu (right-click menu) to use in place of the built-in menu. The shortcut menu can either be assigned for all forms or for just the form that requires it. It is also possible to turn off the shortcut menus for all forms.