| | |
Textbox: On Copy... (VBA in AC2003)
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
This actually pertains to Visual Basic for Application in Access 2003, but I imagine that this forum should yield accurate information for a simple query such as this.
Naturally, the event in the title does not exist. Not for the pre-defined text box control in VB, anyway. However, it is what I'd like to capture.
I have a database that end-users use along side of a mainframe system. A few of the controls in the database forms contain fields that are more readable in one format, but required in another format for input into the mainframe. For example, an account number.
These fields contain dashes ("-") in order to make them more pleasing to the eye, however, when they copy the account and paste it into the mainframe, they can't have the dashes. So, I would like that if I have a field showing "123-45678-90", it would copy "1234567890".
This is easy enough to capture if the user uses Ctrl+C to copy. I'd imagine I could pick that up in the keypress event of the control, pull the clipboard, remove the dashes, and reapply. I don't know how to capture the event that the user highlights, right-clicks, and selects "Copy" from the menu. I considered the possibility of disabling this feature and implementing my own copy button (which would either be in the right-click list if I can add things to it or in an application menu above the form which I know I can do. I'm hoping, however, there is a way to actually capture the copy event, though.
So does anyone know a way to go about this?
Naturally, the event in the title does not exist. Not for the pre-defined text box control in VB, anyway. However, it is what I'd like to capture.
I have a database that end-users use along side of a mainframe system. A few of the controls in the database forms contain fields that are more readable in one format, but required in another format for input into the mainframe. For example, an account number.
These fields contain dashes ("-") in order to make them more pleasing to the eye, however, when they copy the account and paste it into the mainframe, they can't have the dashes. So, I would like that if I have a field showing "123-45678-90", it would copy "1234567890".
This is easy enough to capture if the user uses Ctrl+C to copy. I'd imagine I could pick that up in the keypress event of the control, pull the clipboard, remove the dashes, and reapply. I don't know how to capture the event that the user highlights, right-clicks, and selects "Copy" from the menu. I considered the possibility of disabling this feature and implementing my own copy button (which would either be in the right-click list if I can add things to it or in an application menu above the form which I know I can do. I'm hoping, however, there is a way to actually capture the copy event, though.
So does anyone know a way to go about this?
Last edited by SlyMaelstrom; Mar 3rd, 2009 at 11:43 am.
You probably want to use the KeyUp event on the particular form on which the Ctl+C event occurs. You use this event to test for a combination of keys. You also need to enable the KeyPreview property on the form.
The Shift Code has a value of either 1,2, or 4 when used in a key combination. C will be detected as 67 and the value of the control Key is 2 in the combination scenario.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer) Dim intKC as integer, intShift as Integer, intResult as integer intKC = KeyCode intShift = Shift intResult = intKC + intShift if intResult = 69 then ' Do whatever you want here Keycode = vbnullstring ' Disables the Control C functional ' Replace it with your own. end if End Sub
The Shift Code has a value of either 1,2, or 4 when used in a key combination. C will be detected as 67 and the value of the control Key is 2 in the combination scenario.
Last edited by hkdani; Mar 4th, 2009 at 4:21 pm.
•
•
•
•
but I imagine that this forum should yield accurate information for a simple query such as this.
•
•
•
•
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim intButton as Integer
intButton = Button
Select case intButton
Case 1 ' Left Mouse Button
Case 2 ' Right Mouse Button
' Write Your Code Here
Case 4 ' Middle Mouse Button
'
Case Else
'
End Select
End Sub
But this only covers for clicks on the Active Form. You might have to deal with Buttons, Pictures, etc. I don't know. And some of those controls may not have a built in MouseDown or MouseUp Event. That's where you'll have to get into the Window API's. It get's complicated fast.
I'm not talking about something spawned from a mouse-click event. This event doesn't tell you what you're clicking, it tells you where you're clicking. Even if the event fired when you click on the right-click context menu, which I think it doesn't. I'd have to determine where the Copy button was relative to the menu and the position on the screen, this can naturally vary because if someone does find a way to add or remove buttons from that menu, it will mess up the integrity of the code.
Thanks, again for your reply, however I don't think you are seeing the problem that I have.
Thanks, again for your reply, however I don't think you are seeing the problem that I have.
•
•
•
•
I don't know how to capture the event that the user highlights, right-clicks, and selects "Copy" from the menu.
But I believe this is what you want: You need to write your own DLL in C to handle what you're asking, you need to register that into the VB6 Programming Environment so you can load it as a DLL from the Project Reference Menu, and then just use your DLL in VB6.
It's really simple, if you have 5 years experience in C Programming, 2 years programming Windows APIs, and a little patience: the patience of Job.
Last edited by hkdani; Mar 4th, 2009 at 11:57 pm.
•
•
•
•
You can do that using the Windows API's and C Programming. Your problem is that you're in VB6. That's why they say, if you want finer grain control over what occurs in the program, you should use C or C++!
But I believe this is what you want: You need to write your own DLL in C to handle what you're asking, you need to register that into the VB6 Programming Environment so you can load it as a DLL from the Project Reference Menu, and then just use your DLL in VB6.
It's really simple, if you have 5 years experience in C Programming, 2 years programming Windows APIs, and a little patience: the patience of Job.
Once again, I appreciate your assistance.
•
•
•
•
I think the suggestions that I provided are simplier and more portable than that. This is a distributed MDE. Do you really want me to package a DLL with it for some small copy feature?
Once again, I appreciate your assistance.
There are all kinds of Windows messages generated by a Windows program and that's just one of the messages. And you may not even be able to avoid that behavior, because that may be completely controlled by the executable file.
It's like a sandbox. You can play inside the sandbox, but you're not allowed to play outside that sandbox.
Visual Basic is just that: basic. What you're asking to accomplish goes beyond the basics.
•
•
•
•
It is a small feature, but you have to catch the WindowMessages generated by the Windows operating system to avert the current behavior of the menu click and replace it with your own.
There are all kinds of Windows messages generated by a Windows program and that's just one of the messages. And you may not even be able to avoid that behavior, because that may be completely controlled by the executable file.
It's like a sandbox. You can play inside the sandbox, but you're not allowed to play outside that sandbox.
Visual Basic is just that: basic. What you're asking to accomplish goes beyond the basics.
Thanks again.
•
•
•
•
I know all about event handling. This is not necessary and I'm not sure why you believe it is.
•
•
•
•
I know that I can disable right-click
•
•
•
•
I am almost positiive (sic) that they do.
•
•
•
•
I don't know how to capture the event that the user highlights, right-clicks, and selects "Copy" from the menu.
I'll leave you alone.
![]() |
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: report formula problem.. urgent kindly help
- Next Thread: How to check if form is open
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





