Solved Copy all Date on form to clipboard to user can past this into another system (1 Viewer)

Number11

Member
Local time
Today, 10:18
Joined
Jan 29, 2020
Messages
607
So it it possible to copy the complete form as text into clip board to use can then past into another system?


Private Sub cmd_CopyClipboard_Click()
Me!textbox1.SetFocus
Me!textbox2.SetFocus
Me!textbox3.SetFocus
Me!textbox4.SetFocus
DoCmd.RunCommand acCmdCopy
End Sub

But how wold i also include the text box label :(
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:18
Joined
Oct 29, 2018
Messages
21,358
Hi. You could create an additional Textbox where you could concatenate all the labels and contents of the other Textboxes and copy that one to the Clipboard.
 

Number11

Member
Local time
Today, 10:18
Joined
Jan 29, 2020
Messages
607
Hi. You could create an additional Textbox where you could concatenate all the labels and contents of the other Textboxes and copy that one to the Clipboard.

Sounds a good idea how would i go about doing that ?
 

jdraw

Super Moderator
Staff member
Local time
Today, 06:18
Joined
Jan 23, 2006
Messages
15,364
Number11,
Can you tell us what you want to achieve? There may be options.
If it is a bound form, the data would be in the recordsource of the form. Just saying it depends on what your purpose is.
Good luck.
 

Micron

AWF VIP
Local time
Today, 06:18
Joined
Oct 20, 2018
Messages
3,476
I agree with jdraw. However, if it ends up that you still need the label caption you need to say whether or not the labels are attached to the controls. If they are, it's relatively easy.
 

Number11

Member
Local time
Today, 10:18
Joined
Jan 29, 2020
Messages
607
I agree with jdraw. However, if it ends up that you still need the label caption you need to say whether or not the labels are attached to the controls. If they are, it's relatively easy.

yes good point, so i have a form that has customer details and serial number date of install ect way i would like is to have a button that copies all the information including tables into say a new text box that has selected all copied into clipboard so the user than then past this into another system. this was the user only needs to paste into the other system and not copy line by line is that possible?
 

ebs17

Well-known member
Local time
Today, 11:18
Joined
Feb 7, 2020
Messages
1,883
not copy line by line
A bound form has a RecordsSource. You could take this directly.
With the ADODB method Getstring you can combine the contents of the query into a string and thus pass it on.
 

Number11

Member
Local time
Today, 10:18
Joined
Jan 29, 2020
Messages
607
What is the "Other System"?

customer case notes not access and unable to link have to copy and paste

was thinking something along.. (but this doesn't work :( )

Dim s As String = Me.Label1.Text
Dim a As String = Me.TextBox1.Text
Me.Label1.Text = s
Me.TextBox1.Text = a
Form1.TextBox1.AppendText(Me.TextBox1.Text & vbCrLf & Me.Label1.Text)
Form1.TextBox1.AppendText(Chr(10))
Form1.TextBox1.AppendText(Chr(10))

I would like Copy from say form1 Lable1 along with text1 Date into a new form called say form2 which is just a text box that then has everything within it copied into clipboard so user than then paste it
 
Last edited:

Micron

AWF VIP
Local time
Today, 06:18
Joined
Oct 20, 2018
Messages
3,476
What you suggest is impractical even if it's possible, which I doubt. You need to be less obscure to get focused help, not just say "it's not Access". Can you not make use of a spreadsheet or text file or csv file for the "other" system?
 

moke123

AWF VIP
Local time
Today, 06:18
Joined
Jan 11, 2013
Messages
3,852
heres code I use to copy data to clipboard. Not enough info, as Micron notes, to help you concatenate the data.
Note that Labels dont have a text property. You would use the caption property. You would also not use the text property of a textbox either. Value is the default of a textbox.


Code:
Option Compare Database
Option Explicit

Private Declare Function OpenClipboard Lib "user32.dll" (ByVal hWnd As Long) As Long
Private Declare Function EmptyClipboard Lib "user32.dll" () As Long
Private Declare Function CloseClipboard Lib "user32.dll" () As Long
Private Declare Function IsClipboardFormatAvailable Lib "user32.dll" (ByVal wFormat As Long) As Long
Private Declare Function GetClipboardData Lib "user32.dll" (ByVal wFormat As Long) As Long
Private Declare Function SetClipboardData Lib "user32.dll" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Private Declare Function GlobalAlloc Lib "kernel32.dll" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "kernel32.dll" (ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32.dll" (ByVal hMem As Long) As Long
Private Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyW" (ByVal lpString1 As Long, ByVal lpString2 As Long) As Long

Public Sub SetClipboard(sUniText As String)
    Dim iStrPtr As Long
    Dim iLen As Long
    Dim iLock As Long
    Const GMEM_MOVEABLE As Long = &H2
    Const GMEM_ZEROINIT As Long = &H40
    Const CF_UNICODETEXT As Long = &HD
    OpenClipboard 0&
    EmptyClipboard
    iLen = LenB(sUniText) + 2&
    iStrPtr = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, iLen)
    iLock = GlobalLock(iStrPtr)
    lstrcpy iLock, StrPtr(sUniText)
    GlobalUnlock iStrPtr
    SetClipboardData CF_UNICODETEXT, iStrPtr
    CloseClipboard
End Sub

Public Function GetClipboard() As String
    Dim iStrPtr As Long
    Dim iLen As Long
    Dim iLock As Long
    Dim sUniText As String
    Const CF_UNICODETEXT As Long = 13&
    OpenClipboard 0&
    If IsClipboardFormatAvailable(CF_UNICODETEXT) Then
        iStrPtr = GetClipboardData(CF_UNICODETEXT)
        If iStrPtr Then
            iLock = GlobalLock(iStrPtr)
            iLen = GlobalSize(iStrPtr)
            sUniText = String$(iLen \ 2& - 1&, vbNullChar)
            lstrcpy StrPtr(sUniText), iLock
            GlobalUnlock iStrPtr
        End If
        GetClipboard = sUniText
    End If
    CloseClipboard
End Function
 
Last edited:

Number11

Member
Local time
Today, 10:18
Joined
Jan 29, 2020
Messages
607
I am able to copy to the Clipboard the data from a text box using this

Me.Text1.SetFocus
DoCmd.RunCommand acCmdCopy

if i add this to copy another it just copies that second text2 data

Me.Text2.SetFocus
DoCmd.RunCommand acCmdCopy

how do i move all text box data to a single text box and then copy all data from the text box containing all data
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 10:18
Joined
Jul 9, 2003
Messages
16,245
Now this amused me, I thought your question posed an interesting problem, so I set up a form to demo the problem. I wrote the code off the top of my head for finding a labels caption, and it didn't work. So I did a Google search and it returned my own web-page at the top of the list!

Getting the Caption of a Textbox Label

This was the search term I used:-

I wondered, does Google put my webpage at the top of the list for anyone else, or whether Google knows it's me searching and is is returning results it knows would boost my eGo!

The reason my code failed was because I typed in:- Control, instead of Controls...
 

Number11

Member
Local time
Today, 10:18
Joined
Jan 29, 2020
Messages
607
Now this amused me, I thought your question posed an interesting problem, so I set up a form to demo the problem. I wrote the code off the top of my head for finding a labels caption, and it didn't work. So I did a Google search and it returned my own web-page at the top of the list!

Getting the Caption of a Textbox Label

This was the search term I used:-

I wondered, does Google put my webpage at the top of the list for anyone else, or whether Google knows it's me searching and is is returning results it knows would boost my eGo!

The reason my code failed was because I typed in:- Control, instead of Controls...

Thanks for taking the time to reply.. Yes this is turning my head upside down

So i need to use Me.txtGetMyCaption.Controls(0).Caption to get the text box lable. but i am struggling to find away how to copy all 25 text boxes (with labels) into clipboard any sugegstons?
 

moke123

AWF VIP
Local time
Today, 06:18
Joined
Jan 11, 2013
Messages
3,852
@Uncle Gizmo Using you search phrase Nifty was top of the list. Google must know we're friends.

@Number11 with the code I posted you dont need another textbox. You just need to feed the procedure the proper string.

how do i move all text box data to a single text box and then copy all data from the text box containing all data
You need to concatenate the data.

Code:
dim strSql as string

strSql = Me.Text1 & " " & Me.Text2 & " " & Me.text3

SetClipboard strSql
 

Number11

Member
Local time
Today, 10:18
Joined
Jan 29, 2020
Messages
607
@Uncle Gizmo Using you search phrase Nifty was top of the list. Google must know we're friends.

@Number11 with the code I posted you dont need another textbox. You just need to feed the procedure the proper string.


You need to concatenate the data.

Code:
dim strSql as string

strSql = Me.Text1 & " " & Me.Text2 & " " & Me.text3

SetClipboard strSql

many thanks so i have added PtrSafe as i am running on 64 bit, on compiling i get error Type mismatch on StrPtr ?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 10:18
Joined
Jul 9, 2003
Messages
16,245
Here's an example I knocked up which should go through all the Text box's on your form and concatenate the label and contents of the text box together. However, there is one problem, there is no guarantee it will process them in the correct order. You could try moving them around, you could try examining the controls Tab order, but that might be complicated!

EDIT:- I've updated the sample file to work with copy to clipboard, on both 32 & 64-bit MS Access. I know it works on 64-bit, but I don't know if it works on 32-bit, if anyone could check, would be most grateful!
 

Attachments

  • ExtractTextboxToClipboard_1a.zip
    27.2 KB · Views: 613
Last edited:

Number11

Member
Local time
Today, 10:18
Joined
Jan 29, 2020
Messages
607
Here's an example I knocked up which should go through all the Text box's on your form and concatenate the label and contents of the text box together. However, there is one problem, there is no guarantee it will process them in the correct order. You could try moving them around, you could try examining the controls Tab order, but that might be complicated!

This is great, so how could i copy that into Clipboard
 

moke123

AWF VIP
Local time
Today, 06:18
Joined
Jan 11, 2013
Messages
3,852
So i need to use Me.txtGetMyCaption.Controls(0).Caption to get the text box lable. but i am struggling to find away how to copy all 25 text boxes (with labels) into clipboard any sugegstons?
Loop through the forms control collection and use the Tag property to identify the textboxes you want.

heres an example

edit : UG is faster than me.
 

Attachments

  • CopyPaste.zip
    29.3 KB · Views: 285

moke123

AWF VIP
Local time
Today, 06:18
Joined
Jan 11, 2013
Messages
3,852
This is great, so how could i copy that into Clipboard
I havent looked at Uncles sample but I assume its concatenating the values.
If you look at my sample you'll see I used my above code to copy to clipboard
strSql being the concatenated value.
Code:
SetClipboard strSql
 

Users who are viewing this thread

Top Bottom