Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Nov 2002
    Location
    Belfast, Ireland
    Posts
    339
    Thanks
    2
    Thanked 0 Times in 0 Posts

    OnClick Select All & Copy (XP &/or 2003)

    Hi

    I have an Unbound Text Box that is populated with several fields, e.g., name, address, town, etc. This enables anyone to select the text and paste it into Word or WordPerfect to create a single label, which can then be printed out on our Dymo Label Printer. I'd like to save a user a step or two by making it that they only have to click the Text Box and this would cause an OnClick Event to fire that copies the contents of the Text Box to the Clipboard. A Macro in Word or WordPerfect can then simply paste whatever's on the Clipboard into a document then format the document as a Label and print it.

    So, my question is this: Is it possible to get Access to Select All and Copy to the Clipboard whenever someone clicks the Text Box? I've looked up the VBA Help, and the only thing I could see that resemble this is 'acOLECopy', but adding this to the OnClick Event doesn't work. I don't think it's meant to work this way.

    If it's not possible, then I suppose I can create a form or report and format it to be a label, which can then be accessed by a command button that joins the Form via an ID Field, but I thought that this would be easier and would allow the user to use it in letters as well as just for labels.

    Thanks in advance for your help and advice.

    Brian [img]/forums/images/smilies/smile.gif[/img]

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

    Re: OnClick Select All & Copy (XP &/or 2003)

    Try this, where TextBox1 is the name of the control:

    Private Sub TextBox1_Click()
    Me.TextBox1.SelStart = 0
    Me.TextBox1.SelLength = Len(Me.TextBox1.Text)
    RunCommand acCmdCopy
    End Sub

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: OnClick Select All & Copy (XP &/or 2003)

    How is the textbox being populated? If the user is able to edit it, then you can't safely use the click event because it will fire when they click into the control. You can certainly copy text into the clipboard, but it requires API calls in Access XP. Had you considered simply having Access insert the information directly into the Word document?
    Charlotte

  4. #4
    3 Star Lounger
    Join Date
    Nov 2002
    Location
    Belfast, Ireland
    Posts
    339
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: OnClick Select All & Copy (XP &/or 2003)

    The Text Box is populated by a Function

    Private Function FullName() As String
    FullName = Me!address_title & " " & Me!name & vbNewLine & _
    Me!title & vbNewLine & _
    Forms!frm_branch!name & vbNewLine & _
    Forms!frm_branch!address_1 & vbNewLine & _
    Forms!frm_branch!address_2 & vbNewLine & _
    Forms!frm_branch!town & Forms!frm_branch!postcode
    End Function

    So it can't be edited.

    I had considered sending the data to Word, but we're just about to upgrade to Office 2003, and we may upgrade WordPerfect too, so it's easier to just let the user choose which application they want the data inserted into, etc.

    Hans, is there anything you don't know?

    Anyway, thank you both for your help. As usual, it was right on and lightning fast! <img src=/S/bravo.gif border=0 alt=bravo width=16 height=30>

    P.S. Is there a way to ignore a blank field? Sometimes address_2 has no data. Sorry, forgot to ask in my original post. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

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

    Re: OnClick Select All & Copy (XP &/or 2003)

    If you want to avoid a blank line if an entry is missing, concatenate with + instead of with &:

    FullName = Me!address_title & " " & Me!name & vbNewLine & _
    (Me!title + vbNewLine) & _
    (Forms!frm_branch!name + vbNewLine) & _
    (Forms!frm_branch!address_1 + vbNewLine) & _
    (Forms!frm_branch!address_2 + vbNewLine) & _
    Forms!frm_branch!town & Forms!frm_branch!postcode

  6. #6
    3 Star Lounger
    Join Date
    Nov 2002
    Location
    Belfast, Ireland
    Posts
    339
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: OnClick Select All & Copy (XP &/or 2003)

    Thanks Hans

    I suppose I shouldn't have been so quick to ask, as I realized that I could get the Word or WordPerfect Macro to look for 2 Paragraph Marks/[HRT] codes and just replace them with 1.

    This does, however, look more presentable in Access, so thanks for that. Naturally, it works perfectly. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

Posting Permissions

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