We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Paste to a combo box

walkingbush
walkingbush asked
on
Medium Priority
488 Views
Last Modified: 2013-11-28
Does anyone have a suggestion for quirk free pasting to a combo box? I have a form which my users want to be able to copy and paste a project number from a previous form into a combo box on the new form. The numbers paste in but then we get a not-in-list flag, even though the value is in the list. If you paste the value in, backspace the last number and re-enter it, everything works fine. Not sure what is required to make this work all the time. Any suggestions are appreciated!

Thanks!
Michael
Comment
Watch Question

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
Sounds like the paste string has extra characters, apparently hidden ... possibly a Line Feed and/or Carriage Return.

I would suggest.

See this link:

http://www.mvps.org/access/api/api0049.htm

The, create a custom right click menu - just for the combo box ... that will call a function (using the code above) that gets the clipboard value ... then you use the Replace() function to strip out an LF's and CR's ... may tabs, etc ...  then set the remain value into the combo.

I recently had to do a similar thing.

mx
Jeffrey CoachmanMIS Liason
CERTIFIED EXPERT
Most Valuable Expert 2012

Commented:
Also,

Instead of doing a copy and paste  from one form to another (which can be unreliable depending on the version of Office and anything else that might be in/on the users clipboard), why not simply code it in?

In the "Source" form, insert a "Copy To:" button.
Use code similar to this:

    Forms!frmDestination!txtDestination = Trim(Me.txtSource)

This bypasses any interaction with the clipboard and does a Trim to remove any leading or trailing spaces.
(You will still be advised to Use MX's "Replace" code to catch and oddball  LF's and CR's )

;-)

JeffCoachman

Here is a sample

JeffCoachman


db65.mdb

Author

Commented:
From a users standpoint, that isn't a very acceptable solution but oh well. I'll see what I can come up with. Thanks!
Michael
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
You don't have much choice.  Clearly what is being copied to the clipboard has erroneous characters present.  You need to strip them out.  And from my users stand point, it's a beautiful thing.

Control C to the Clipboard.
Right click over the text box - one menu item ... Paste Special.

mx
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
Here is the easy way to create custom menus and toolbars and right click menus (aka Pop Ups):

http://www.jamiessoftware.tk/articles/menubars.html
       
Not sure it that article mentions it, but ... when you are in the Customize mode (dialog) ... if you hold down the Control key, you can drop and drag (ie, copy) menu items from one place to another ... handy for making a new menu that is similar another one.

mx

Author

Commented:
Oh, I understand from a programming perspective. It makes total sense. I'll give your suggestion a try but I've learned that if ctrl+c then ctrl+v doesn't work, someone is going to have a fit. What's weird is that they are selecting a numeric field (ProjNum) from a form utilizing the same record source as the time sheet form they are trying to paste to. Is it possible that it is being pasted as text instead of numeric data? Could that cause the problem?
Michael
Commented:
Could you use the Notinlist event to strip the extra characters

ie

Private Sub Combo2_NotInList(NewData As String, Response As Integer)
Combo2 = Val(Combo2.Text)
Response = acDataErrContinue
End Sub

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
CERTIFIED EXPERT
Top Expert 2007

Commented:
That's an excellent idea ... and does seem to work.

mx
Jeffrey CoachmanMIS Liason
CERTIFIED EXPERT
Most Valuable Expert 2012

Commented:
walkingbush,

Who were you referring to in post:
http:#a23595505
?
JeffCoachman
Jeffrey CoachmanMIS Liason
CERTIFIED EXPERT
Most Valuable Expert 2012

Commented:
klilley,

Great solution.
;-)

Jeff
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.