Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 2nd, 2005, 11:36 AM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Capturing the Control + C event

I need to capture the Control - C event and I'm not sure how to do it. I'm currently capturing the Return/Enter event. Is there a way to do this? My code is below.

Private Sub lstResults_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then 'Return/Enter key
        lstResults_DblClick (False)
    ElseIf 'this is where I need to capture the Control + C event to enable users to copy.
    End If
End Sub

Once I've trapped this event, how can I allow the user to actually copy a specified variable?

I hope this is enough info to enable you to help me. If not I can try to better describe what I'm trying to do.

Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old June 2nd, 2005, 03:27 PM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Quote:
quote:Originally posted by Sammy8932
Once I've trapped this event, how can I allow the user to actually copy a specified variable?
I don't understand why you're trying to reinvent the wheel. If the user highlights said variable and presses Control+C, it WILL copy the variable into the buffer. No need to program anything.

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote
  #3 (permalink)  
Old June 3rd, 2005, 07:15 AM
Friend of Wrox
 
Join Date: Nov 2004
Location: Seattle, WA, .
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

Assuming there is really a reason you what to do this, just check for:

(KeyCode = vbKeyC) And ((Shift and acCtrlMask) > 0)

I assume you need this for getting the data into a variable in your code not into the copy/paste buffer for the user to use.

Of course another reason might be that you want to automatically copy all of the text into the copy/paste buffer. This would be a nice feature since when a field is clicked (rather than tabbed into) it doesn't automatically select all of the text. If this is what you want to do, then the code for when a Ctrl+C is pressed is:

Me.field.SelStart = 0
Me.field.SelLength = Len(Me.field)

BTW, you can't use the GotFocus event to make sure all of the text gets selected when a user clicks into a field. The click somehow overrides the GotFocus as far as selecting text goes. Though you might be able to trap the MouseDown or MouseUp events to do this. I've just given up trying to make this work the way I want.

You might also be wanting to use this to prevent the user from copying something into the copy/paste buffer. If so, then the code for when a Ctrl+C is pressed is:

KeyCode = 0

Of course as Greg says, if this is a simple copy of the text the user has selected, why reinvent the wheel? And keep in mind that if you trap the key because you're trying to automatically copy all of the text, the user will never be able to copy just the part of the text that they select. Of course a way around this would be to check the SelLength before you reset the SelStart and SelLength. If SelLength is GT zero, don't reset anything.

Just curious, what are you really trying to do when you trap Ctrl+C?

Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org
Reply With Quote
  #4 (permalink)  
Old June 3rd, 2005, 08:25 AM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I figured out how to trap it. I need to enable the user to be able to copy a variable (the phone number) out of the list box. I'm not sure how to do this. Below is the code that's used to fill the list box (PhoneNumberListBx):
ctl!PhoneNumberListBx.RowSource = "SELECT phone_id, phone_desc, FormatPhone(phone_number) FROM dbo_vwOrgPhone " _
& strWhere & " ORDER BY phone_desc;"

When I click on the list box and Control - C, it only copies the first column. Which is not the phone number. The phone number is in the 3rd column. Maybe I'm going about this all wrong. I'm fairly new to this so please bear with me.

Can anyone help me out on this? I appreciate your help.

Let me know if there are any questions.

Thanks.
Reply With Quote
  #5 (permalink)  
Old June 3rd, 2005, 09:03 AM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by rjweers



I assume you need this for getting the data into a variable in your code not into the copy/paste buffer for the user to use.
rjweers, what I need to do is get the Phone Number on the List box into the copy/paste buffer for the user to use. Can you tell me how to do this?

Thanks

Reply With Quote
  #6 (permalink)  
Old June 4th, 2005, 08:20 AM
Friend of Wrox
 
Join Date: Nov 2004
Location: Seattle, WA, .
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

Ah ha! A bit more tricky, eh? Obviously, when the user presses Ctrl+C they get the value of the bound column, not the text of the item that is selected.

So there's one option. Make the phone number field the bound column. I'm not sure why the phone number can't be the bound column in the list box. But apparently, since you're doing something with a doubleclick, the list box uses the bound column to do some other work.

So, as you said, what you really want to do is simply put the phone number into the clipboard. So here's an MSKB article for doing just that: http://support.microsoft.com/default...kb;en-us;96900 Be aware that the code there has some minor errors when it comes to the underscore (_) continuations. VBA requires a space before an underscore that is used as a continuation character.

It looks like fairly easy code to use. But if you can get around having to do that by binding the phone number, that's probably your best bet. You can easily do this and still keep the currently bound field in your list. You'll just have to change your code that uses that bound column to use Me.lstResults.Column(0) (assuming your current bound column is 1).

BTW, if you choose not to change the bound column and do the copy to the clipboard, you can get at the value of the phone number by using Me.lstResults.Column(i) where "i" is the index of the column of the phone number and the first column in a list box is zero (like the default for any array). This method saves writing code that uses the bound column to lookup information that is already available in the list.

NOTE: I found the MSKB article by going to http://search.microsoft.com and typing the search string: clipboard access. The article was the first on the list. (Yes, true to my nature, I'm still trying to teach you all how to fish rather than giving you the fish.)
Reply With Quote
  #7 (permalink)  
Old June 6th, 2005, 08:42 AM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply rjweers. I'll talk to the person who developed the application to see if it would be a problem to change the bound column and if it is, I'll try to put the phone number into the clipboard. Thank you very much for your help. I appreciate it.

I do search for the answers myself and only post my problems when I can't figure it out on my own. There are times (as in this one) I'm not sure what to even search on. Again, thanks for your help. Hopefully I can get this to work. :)

Reply With Quote
  #8 (permalink)  
Old June 7th, 2005, 09:02 AM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I ended up not needing to put the phone number into the clipboard. I was able to change the bound column to the phone number column. I then captured the Control-C event and used DoCmd.RunCommand acCmdCopy to copy the phone number. Thanks rjweers for your help.

Reply With Quote
  #9 (permalink)  
Old June 8th, 2005, 09:05 AM
Friend of Wrox
 
Join Date: Nov 2004
Location: Seattle, WA, .
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

It's nice when things work out the easy way...

But now it's time to go back to Greg's post. With the way you now have the combobox set up (having phone be the bound column), you don't need to capture Ctrl+C. Just let the built-in functionality of Windows do it for you. Even easier!!!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mouse event capturing in IE6 using VB6 amyourpet VB How-To 0 January 25th, 2008 08:01 AM
Capturing a "Enter" key event in C# windows applic bhavna VS.NET 2002/2003 1 March 15th, 2007 07:45 AM
Capturing the onkeydown event richard.york Javascript How-To 5 December 27th, 2005 04:27 PM
Capturing Mouse Click Event whiterainbow ASP.NET 1.0 and 1.1 Professional 1 December 8th, 2005 01:44 AM



All times are GMT -4. The time now is 12:47 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.