943,680 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Mar 3rd, 2009
0

Textbox: On Copy... (VBA in AC2003)

Expand Post »
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?
Last edited by SlyMaelstrom; Mar 3rd, 2009 at 11:43 am.
Reputation Points: 15
Solved Threads: 2
Newbie Poster
SlyMaelstrom is offline Offline
21 posts
since Oct 2005
Mar 4th, 2009
0

Re: Textbox: On Copy... (VBA in AC2003)

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.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
  2. Dim intKC as integer, intShift as Integer, intResult as integer
  3.  
  4. intKC = KeyCode
  5. intShift = Shift
  6. intResult = intKC + intShift
  7.  
  8. if intResult = 69 then
  9. ' Do whatever you want here
  10. Keycode = vbnullstring ' Disables the Control C functional
  11. ' Replace it with your own.
  12. end if
  13. 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.
Reputation Points: 49
Solved Threads: 44
Posting Pro in Training
hkdani is offline Offline
426 posts
since Nov 2007
Mar 4th, 2009
0

Re: Textbox: On Copy... (VBA in AC2003)

Thanks, as I said in my original post, I can handle Ctrl-C on a key-press event. The problem is handing the right-click option. I don't want to leave any loose ends for the end-user to complain about when it goes into production.
Reputation Points: 15
Solved Threads: 2
Newbie Poster
SlyMaelstrom is offline Offline
21 posts
since Oct 2005
Mar 4th, 2009
0

Re: Textbox: On Copy... (VBA in AC2003)

Quote ...
but I imagine that this forum should yield accurate information for a simple query such as this.
Try the mousedown or mouseUP event. They are about the same as the KeyUP and KeyDown Events.

Quote ...
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
The Shift parameter reflects whether the Shift, Ctl, or Alt key were pressed in conjunction with the Mouse Button: with values of 1, 2, and 4 respectively.

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.
Reputation Points: 49
Solved Threads: 44
Posting Pro in Training
hkdani is offline Offline
426 posts
since Nov 2007
Mar 4th, 2009
0

Re: Textbox: On Copy... (VBA in AC2003)

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.
Reputation Points: 15
Solved Threads: 2
Newbie Poster
SlyMaelstrom is offline Offline
21 posts
since Oct 2005
Mar 4th, 2009
0

Re: Textbox: On Copy... (VBA in AC2003)

Quote ...
I don't know how to capture the event that the user highlights, right-clicks, and selects "Copy" from the menu.
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.
Last edited by hkdani; Mar 4th, 2009 at 11:57 pm.
Reputation Points: 49
Solved Threads: 44
Posting Pro in Training
hkdani is offline Offline
426 posts
since Nov 2007
Mar 6th, 2009
0

Re: Textbox: On Copy... (VBA in AC2003)

Click to Expand / Collapse  Quote originally posted by hkdani ...
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.
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.
Reputation Points: 15
Solved Threads: 2
Newbie Poster
SlyMaelstrom is offline Offline
21 posts
since Oct 2005
Mar 6th, 2009
0

Re: Textbox: On Copy... (VBA in AC2003)

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.
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.
Reputation Points: 49
Solved Threads: 44
Posting Pro in Training
hkdani is offline Offline
426 posts
since Nov 2007
Mar 6th, 2009
0

Re: Textbox: On Copy... (VBA in AC2003)

Click to Expand / Collapse  Quote originally posted by hkdani ...
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.
Yeah, believe me. I was taught on C++. I know all about event handling. This is not necessary and I'm not sure why you believe it is. I didn't ask to change how copy functionality, there is no need to do that. All you have to do is prevent the user from accessing the standard copy functionality in the form. There is three ways for them to do this. One is Ctrl+C which we know we can handle with a KeyUp event. They can access it from the top menu bar, which will be disabled in the MDE, so that's not an issue. The third way is right clicking on a control. To be completely blunt, I know that I can disable right-click and am willing to do it. So if you can't find anything simpiler than that, then there is no point in attempting it. The other alternative is if Access provides functionality to edit the right-click menu in VBA. I am almost positiive that they do. Anyway, don't concern yourself with this anymore, I might as well just review all the API documentation at this point to find what I'm looking for.

Thanks again.
Reputation Points: 15
Solved Threads: 2
Newbie Poster
SlyMaelstrom is offline Offline
21 posts
since Oct 2005
Mar 6th, 2009
0

Re: Textbox: On Copy... (VBA in AC2003)

Quote ...
I know all about event handling. This is not necessary and I'm not sure why you believe it is.
Windows is an event driven environment.

Quote ...
I know that I can disable right-click
I'd be interested in your future post about how you are able to do this.

Quote ...
I am almost positiive (sic) that they do.
If you knew, you wouldn't be saying almost. Almost only counts in horseshoes.

Quote ...
I don't know how to capture the event that the user highlights, right-clicks, and selects "Copy" from the menu.
You can't capture that in VB6 let alone from VBA. And I really doubt Access casts some magic functionality spell on VBA giving it more power than VB6.

I'll leave you alone.
Reputation Points: 49
Solved Threads: 44
Posting Pro in Training
hkdani is offline Offline
426 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: report formula problem.. urgent kindly help
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC