Results 1 to 12 of 12
  1. #1
    MikeAllen is offline Novice
    Windows Vista Access 2000
    Join Date
    Aug 2012
    Posts
    9

    Copy button on a form

    Hi all, hope someone can help me.



    Is it possible to create a command button on a form that when clicked will copy the data in a specific text box (the button would be situated on the form next to the field)?

    I imagine it would involve some VBA?

    The field in question is called 'txbuserid'

    Thanks
    Mike
    Last edited by MikeAllen; 08-28-2012 at 01:52 PM. Reason: spelling error

  2. #2
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Well a lot of this is going to depend on where you want the data to ultimately end up.


    Where you want the data to go = Forms("formname").txbuserid.Value

    in my case I wanted to copy things from a text box to an IE window place... The code below will have nothing to do with what you are doing, but it shows my method.

    Code:
    Sub CopytoSM()
    
    
      Dim oCsM As InternetExplorer
      Set oServMan = GetServMan
      
      With oServMan.Document.frames(0).Document.all
        .Item("X93").Value = Forms("frmDauto").txtAdgidentifier.Value
      End With
    End Sub

  3. #3
    MikeAllen is offline Novice
    Windows Vista Access 2000
    Join Date
    Aug 2012
    Posts
    9
    Hi redbull, thanks for the quick reply. I actually don't want the data to go external to the database, it's going to be pasted into a field in a different form within the same database so I just want it to sit on the clipboard.
    I've tried linking but both forms are bound to different tables. Or is there an easier way to link the field so the data can automatically be brought through to the next form?
    I'm rubbish at explaining these things.
    Mike

  4. #4
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Ahh, I understand. let me ask you something... are both forms going to be open at the same time? or does the first form completely shut down then the second form opens? Just wondering, I have used one form to another copy before... but the whole clipboard Idea, I've never done.

    However I was reading something on here about the clipboard.

    http://www.cpearson.com/excel/clipboard.aspx

    Looks like you can assign certain text to a clipboard... so instead of assigning text.. you could try...


    Putting Text In The Clipboard
    Code:
    Dim DataObj As New MSForms.DataObject
    Dim S As String
    S = Forms("formname").txbuserid.Value    
    DataObj.SetText S
    DataObj.PutInClipboard
    Retrieving Text From The Clipboard

    Code:
     
    Dim DataObj As New MSForms.DataObject
    Dim S As String
    DataObj.GetFromClipboard
    S = DataObj.GetText   
    Debug.Print S


    Have to give credit to June7 for digging up the Link.

    --Website directions... this has to be done in order for this to work

    "The MSForms library contains an object called the DataObject that provides support for working with text strings on the Windows clipboard. VBA does not support the data type required for other, non-text, values on the clipboard. To use the DataObject in your code, you must set a reference to the Microsoft Forms 2.0 Object Library.
    ADDING A REFERENCE IN VBA. To add a reference to your VBA project, go to the Tools menu in the VBA editor and choose the References item. In the dialog that appears, scroll down the list until you find the appropriate library. Commonly used references are listed at the top of the list, and after those, the references are listed in alphabetical order. When you find the reference required by the code, check the checkbox next to the reference title and then click OK."
    Last edited by redbull; 08-28-2012 at 02:22 PM. Reason: Amendment

  5. #5
    MikeAllen is offline Novice
    Windows Vista Access 2000
    Join Date
    Aug 2012
    Posts
    9
    I'll give it a go, cheers redbull.
    And credit to June7 for digging up the link.
    Mike

  6. #6
    MikeAllen is offline Novice
    Windows Vista Access 2000
    Join Date
    Aug 2012
    Posts
    9
    Thanks for the update also.
    Mike

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    To press a button and place a given Control's value in the Clipboard:

    Code:
    Private Sub btnCopyField_Click()
     If Nz(Me.TargetField, "") <> "" Then
      TargetField.SetFocus
      TargetField.SelStart = 0
      TargetField.SelLength = Len(Me.TargetField)
      DoCmd.RunCommand acCmdCopy
     End If
    End Sub


    Linq ;0)>

  8. #8
    MikeAllen is offline Novice
    Windows Vista Access 2000
    Join Date
    Aug 2012
    Posts
    9
    Cheers Linq, I have a couple of options to try now, great.
    In your code, does the Nz have a specific meaning?
    Cheers
    Mike

  9. #9
    MikeAllen is offline Novice
    Windows Vista Access 2000
    Join Date
    Aug 2012
    Posts
    9
    Linq, tried this because it's the quickest out of the two options I have. However, when I click the button and then paste into a different field it's copying the name of the field and not the data within it.
    Mike

  10. #10
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Sorry, but if you're talking about the code I gave you, that makes no sense whatsoever!

    What exact code did you use?

    Linq ;0)>

  11. #11
    MikeAllen is offline Novice
    Windows Vista Access 2000
    Join Date
    Aug 2012
    Posts
    9
    Linq, my apologies. It did work, not sure what happened there.
    One more question: Once I paste the data is there any way the data can aoutomatically be removed from the clipboard ro does it just stay there until the button is clicked again?
    Cheers
    Mike

  12. #12
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    It normally would stay there until you copy something else; that's a Windows thing. But if you know where/what Control you're going to be Pasting it into, you could program it to empty after leaving that Control.

    Placed this code at the top of the Form's Code Module (the Form you'll be Pasting into) just under the

    Option Compare Database

    Statement.

    Code:
    Private Declare Function OpenClipboard Lib "user32" (ByVal hWnd As Long) As Long
    Private Declare Function CloseClipboard Lib "user32" () As Long
    Private Declare Function EmptyClipboard Lib "user32" () As Long


    Then in the OnExit event of the recipient Control

    Code:
    Private Sub FieldToPasteInto_Exit(Cancel As Integer)
    
     'Open, Empty and Close Clipboard
    
      Call OpenClipboard(0&)
      EmptyClipboard
      CloseClipboard
    
    End Sub


    Linq ;0)>

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

Similar Threads

  1. Replies: 5
    Last Post: 02-21-2012, 07:33 AM
  2. Replies: 3
    Last Post: 02-11-2012, 11:17 AM
  3. Replies: 3
    Last Post: 05-23-2011, 07:29 AM
  4. Replies: 10
    Last Post: 03-21-2011, 02:46 PM
  5. Replies: 1
    Last Post: 07-27-2010, 02:27 PM

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