InsertText 方法

expandtri全部显示

blueup应用于 Module 对象的 InsertText 方法。

InsertText 方法在标准模块类模块中插入一个指定的文本字符串

expression.InsertText(Text)

expression     必需。返回以上对象之一的表达式。

Text     必需 String 型。要插入到模块中的文本。

blueup应用于 Application 对象的 InsertText 方法。

InsertText 方法将指定的文本字符串插入到应用程序中。

expression.InsertText(Text, ModuleName)

expression     必需。返回以上对象之一的表达式。

Text     必需 String 型。要插入到模块中的文本。

ModuleName     必需 String 型。应用程序的模块名。

说明

当使用 InsertText 方法来插入字符串时,Microsoft Access 将把新文本放在模块尾部,所有其他过程之后。

若要一次添加多行,请在组成 text 参数的字符串中需要分行的位置包含固有常量 vbCrLf。该常量将强制换行。

若要指定在某行插入文本,请使用 InsertLines 方法。如果要在模块的声明节插入过程代码,请使用 InsertLines 方法,不要用 InsertText 方法。

注释  在 Microsoft Access 的旧版本中,InsertText 方法是 Application 对象的方法。虽然仍可以使用 Application 对象的 InsertText 方法,但是建议改用 Module 对象的 InsertText 方法。

示例

blueup应用于 Module 对象。

下面的示例在标准模块中插入文本字符串:

Function InsertProc(strModuleName) As Boolean

   Dim mdl As Module, strText As String

   On Error GoTo Error_InsertProc

   ' Open module.

   DoCmd.OpenModule strModuleName

   ' Return reference to Module object.

   Set mdl = Modules(strModuleName)

   ' Initialize string variable.

   strText = "Sub DisplayMessage()" & vbCrLf _

       & vbTab & "MsgBox ""Wild!""" & vbCrLf _

       & "End Sub"

   ' Insert text into module.

   mdl.InsertText strText

   InsertProc = True

Exit_InsertProc:

   Exit Function

Error_InsertProc:

   MsgBox Err & ": " & Err.Description

   InsertProc = False

   Resume Exit_InsertProc

End Function