Results 1 to 5 of 5
  1. #1
    Nailati is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    15

    How to copy a number to the clipboard--without hyphens?

    Greetings. Here's my situation: I have a library database containing hyphenated book numbers (TMINs). I often copy and paste these numbers into other programs. Some of these require the TMIN that I input to be hyphenated and some require it to be unhyphenated.



    On my main publication info form, I have a button next to the TMIN that copies it (hyphens included) to the clipboard--works great. However, I would like a second button to copy it, but without the hyphens.

    I know the hyphens can be removed with the Replace() function, but I'm not sure how to apply that to something that will not be displayed, only copied to the clipboard.

    Here's the code for the button I have working (copies the TMIN as-is):

    Private Sub BtnCopyTMIN_Click()
    Me!FieldTMIN.SetFocus
    DoCmd.RunCommand acCmdCopy
    End Sub

    Any ideas on how I can work the Replace() function in there, without changing my actual data? Thanks!

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I don't have acc2007, but I'd try

    -adding a variable TMIN_NoHyphens
    -TMIN_NoHyphens = Replace (Me.FieldTMIN,"-","")
    and then copy that.

    Just a guess/suggestion

  3. #3
    Nailati is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    15
    Quote Originally Posted by orange View Post
    I don't have acc2007, but I'd try

    -adding a variable TMIN_NoHyphens
    -TMIN_NoHyphens = Replace (Me.FieldTMIN,"-","")
    and then copy that.

    Just a guess/suggestion
    Thanks so much--that sent me down the right path. I found a (ugly but effective) solution to getting the variable onto the clipboard here. Basically I have to take the variable, stick it in a size 0 field on the form, set focus to that field, and then copy. This seems to work:

    Private Sub BtnCopyTMIN2_Click()

    Me!FieldTMIN.SetFocus
    TMIN_NoHyphens = Replace(Me.FieldTMIN, "-", "")
    Me.InvisibleBox = TMIN_NoHyphens
    Me.InvisibleBox.SetFocus
    DoCmd.RunCommand acCmdCopy

    End Sub

    Thanks again, I didn't even really know where to start.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    You are welcome. Glad you have it working.

  5. #5
    Nailati is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    15
    I just wanted to add something to this in case anyone has a similar situation.

    The button wouldn't work if my cursor was already in the TMIN field. Or, if I'd highlighted some part of the TMIN, it would only copy that part.

    I got around this by adding a line to the code telling it to focus on another field (at random) and then on the TMIN field. Ugly coding, I know! -- but at least it works.

    Private Sub BtnCopyTMIN2_Click()

    Me!FieldRev.SetFocus
    Me!FieldTMIN.SetFocus
    TMIN_NoHyphens = Replace(Me.FieldTMIN, "-", "")
    Me.InvisibleBox = TMIN_NoHyphens
    Me.InvisibleBox.SetFocus
    DoCmd.RunCommand acCmdCopy

    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Importing from clipboard?
    By mrrrgh in forum Access
    Replies: 5
    Last Post: 04-27-2012, 11:36 AM
  2. Replies: 5
    Last Post: 04-19-2012, 10:41 AM
  3. Replies: 8
    Last Post: 05-26-2011, 09:23 AM
  4. Use VBA to copy table contents to the clipboard?
    By Deutz in forum Programming
    Replies: 3
    Last Post: 10-21-2010, 10:59 PM
  5. Replies: 1
    Last Post: 03-13-2010, 08:38 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums