tags:

views:

605

answers:

6

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?

+2  A: 

It sounds like you may need to rethink your interface. Can you provide more info. on what you want to happen?

Galwegian
A: 

Which event are you using for the pop-up box?

Remou
A: 

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.

FirebirdVII1963
+1  A: 

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
Remou
A: 

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?

FirebirdVII1963
+1  A: 

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.

Remou
Will that catch a ctrl-V as well?
CodeSlave
Sadly, no. It is by no means neat.
Remou
If you'd take this route, and catching CTRL+V would be the only remaining problem to solve, I think it could be done using KeyPress (or KeyUp) event handler, couldn't it? Not neat, but...
Yarik
Catching Ctrl-V is covered in an earlier post.
Remou