Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Jun 2004
    Location
    Banglamung, Thailand
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Copy text to clipboard (Access 2003 SR 1)

    Subject edited by HansV to be more descriptive than 'Access'

    I have compiled a database wiht Access 2003 which consists of a variety of different fields. Two of the fields are for storing USER ID and Password for use when visiting web sites associated with that particular record.
    What I would like to do, and so far have drawn a blank, is to create a button next to each of these fields which, when clicked will copy the information in the respective field for pasting into a web site log on box.
    Does anyone have any script which will do this or can suggest how to do this is a neat way?

    Thanks in advance

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Copy text to clipboard (Access 2003 SR 1)

    You can find code to manipulate the Windows clipboard in API: Copy variables/control contents to memory on the Access Web. The code provided there should be copied into a standard module. To copy the contents of a text box named txtUserID to the Windows clipboard, use something like this:

    Private Sub cmdCopyUserID_Click()
    ClipBoard_SetText Me.txtUserID
    End Sub

    The user will still have to press Ctrl+V in the appropriate text box on the web page to paste the text.

  3. #3
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Copy text to clipboard (Access 2003 SR 1)

    Sheez....thats a long piece of code. I'd think that there would be some easier way to simply get text copied to the clipboard. It is (under normal circumstances).. a common procedure, that you may expect a person will want to automate. I find it strange that it is so involved.

    (Just my thoughts....not complaining!!!) <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    Regards,
    Rudi

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Copy text to clipboard (Access 2003 SR 1)

    Access VBA does not have built-in support for manipulating the clipboard, but it does have equivalents for menu items such as Edit | Copy and Edit | Paste. You could use those, but - as noted in the Access Web article I posted a link to - you must set focus to the text box and select the text in it:

    Private Sub cmdCopyUserID_Click()
    With Me.txtUserID
    .SetFocus
    .SelStart = 0
    .SelLength = Len(.Text)
    End With
    RunCommand acCmdCopy
    End Sub

    Although this is much shorter, it may not always be desirable to shift the focus and to select text in a text box. The API code is longish, but you only need to copy it into a module and use it, you don't need to understand how it works.

  5. #5
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Copy text to clipboard (Access 2003 SR 1)

    <hr>you don't need to understand how it works<hr>
    If I needed to, I'd study it. But for now.....Thank goodness. <img src=/S/groovin.gif border=0 alt=groovin width=21 height=21>

    2 Questions on your sample code!
    .SelLength = Len(.Text)

    1. I assume the .text also links to the with statement; IOW - txtUserID.text? (This is interesting; didn't realize you can have 2 referals in the same line!)
    2. I always specified a random number in the SelLength. I just put SelLength = 1000 (knowing text will never exceed that!). Does the Len function in your example count that characters and select up to that?

    Tx
    Regards,
    Rudi

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Copy text to clipboard (Access 2003 SR 1)

    1. Everything starting with a period within the With Me.txtUserID ... End With block refers to Me.txtUserID. It doesn't matter whether you have one or two or five items on a line that start with a period, they will all refer to Me.txtUserID.

    2. As you guessed, Len(.Text) counts the exact number of characters in the text box. I could have used an arbitrary large number instead. You don't get an error message if you set SelLength to a number larger than the actual number of characters in the text box.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •