Using Clipboard from VB coding

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to put the contents of a (form) field into the clipboard?

I want to stuff a number into the clipboard when I open a form.

Thanks,

John H W
 
Hi John,

Have a look at the following from one of my applications.

I have a form that has an address on it, the user can click a command button
to open a popup form that is passed the address as an argument that is used
to prefill a textbox. The user can then do a final edit to the details then
click the command button 'cmdCopy', which after some basic checks passes the
text to the Windows Clipboard.

Hope you find it usefull.

Regards


Private Sub cmdCopy_Click()
If IsNull(Me.txtCopyBox) Or Me.txtCopyBox = "" Then
Me.txtCopyBox.SetFocus
Exit Sub
Else
Me.txtCopyBox.SetFocus
If Me.txtCopyBox.SelLength = 0 Then
' Ignore, nothing selected
Me.txtCopyBox.SetFocus
Else
' Copy to Windows Clipboard
If Me.txtSelLength = 0 Or IsNull(Me.txtSelLength) Then
' User just clicked into txtCopyBox and not selected
MsgBox "You have not selected anything to copy." & vbCrLf &
vbCrLf & _
"Please make your selection and press the Copy button
again.", _
vbOKOnly + vbInformation, "Nothing Selected"
Me.txtCopyBox.SetFocus
Me.txtSelStart = Me.txtCopyBox.SelStart
Me.txtSelLength = Me.txtCopyBox.SelLength
Exit Sub
End If
Me.txtCopyBox.SetFocus
Me.txtCopyBox.SelStart = Me.txtSelStart
Me.txtCopyBox.SelLength = Me.txtSelLength
DoCmd.RunCommand acCmdCopy
End If
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top