在Access 2007中使用VBA复制文本
我试图将在Access 2007中使用VBA复制文本,vba,ms-access,ms-access-2007,Vba,Ms Access,Ms Access 2007,我试图将strContents复制到剪贴板中,但我做不到。 我的代码是: Dim value_currency As Variant Dim strContents As String value_currency = value_currency_txt.value strContents = NumberToString(value_currency) & " (" & Format(value_currency_txt.Value, "Currency") & "
strContents
复制到剪贴板中,但我做不到。
我的代码是:
Dim value_currency As Variant
Dim strContents As String
value_currency = value_currency_txt.value
strContents = NumberToString(value_currency) & " (" & Format(value_currency_txt.Value, "Currency") & ")"
DoCmd.RunCommand acCmdCopy
NumberToString
将数字转换为字符串
当我使用MsgBox strContents
时,会得到所需的结果,但当我尝试复制strContents
时,会出现错误2406-命令副本现在不可用
如何将文本复制到剪贴板中?如果以下操作可行,则此问题为:
如果您手头有表单,可以使用以下简单方法: 您可以轻松发送命令,将表单文本框中当前选定的文本复制到剪贴板:
DoCmd.RunCommand acCmdCopy
在主窗体上创建一个按钮和一个(微小的)文本框:btnClip和txtClip
将此代码分配给按钮:
Private Sub btnClip_Click()
Dim strClip As String
' Empty textbox to copy from.
Me.txtClip.Value = Null
' Retrieve your data.
strClip = "Some text to copy for later pasting."
If Len(strClip) > 0 Then
' Insert the text in the textbox where it can be copied.
Me.txtClip.Value = strClip
' Move focus to the textbox which will select all text.
Me.txtClip.SetFocus
' Copy the selected text to the clipboard.
DoCmd.RunCommand acCmdCopy
' Return focus to the button.
Me.btnClip.SetFocus
End If
End Sub
诀窍是小文本框txtClip。它可以放在任何地方,甚至不需要大小;它可以是零x零。它给出了错误用户定义类型未定义。我认为MSForms.Dataobjects有问题,我不得不从WindowsSystem32添加FM20.dll作为参考
Private Sub btnClip_Click()
Dim strClip As String
' Empty textbox to copy from.
Me.txtClip.Value = Null
' Retrieve your data.
strClip = "Some text to copy for later pasting."
If Len(strClip) > 0 Then
' Insert the text in the textbox where it can be copied.
Me.txtClip.Value = strClip
' Move focus to the textbox which will select all text.
Me.txtClip.SetFocus
' Copy the selected text to the clipboard.
DoCmd.RunCommand acCmdCopy
' Return focus to the button.
Me.btnClip.SetFocus
End If
End Sub