편집

다음을 통해 공유


Module.InsertLines method (Access)

The InsertLines method inserts a line or group of lines of code in a standard module or a class module.

Syntax

expression.InsertLines (Line, String)

expression A variable that represents a Module object.

Parameters

Name Required/Optional Data type Description
Line Required Long The number of the line at which to begin inserting.
String Required String The text to be inserted into the module.

Return value

Nothing

Remarks

To add multiple lines, include the intrinsic constant vbCrLf at the desired line breaks within the string that makes up the String argument. This constant forces a carriage return and line feed.

When you use the InsertLines method, any existing code at the line specified by the Line argument moves down.

Lines in a module are numbered beginning with one. To determine the number of lines in a module, use the CountOfLines property.

Example

The following example creates a new form, adds a command button, and creates a Click event procedure for the command button.

Function ClickEventProc() As Boolean 
 Dim frm As Form, ctl As Control, mdl As Module 
 Dim lngReturn As Long 
 
 On Error GoTo Error_ClickEventProc 
 ' Create new form. 
 Set frm = CreateForm 
 ' Create command button on form. 
 Set ctl = CreateControl(frm.Name, acCommandButton, , , , _ 
 1000, 1000) 
 ctl.Caption = "Click here" 
 ' Return reference to form module. 
 Set mdl = frm.Module 
 ' Add event procedure. 
 lngReturn = mdl.CreateEventProc("Click", ctl.Name) 
 ' Insert text into body of procedure. 
 mdl.InsertLines lngReturn + 1, vbTab & "MsgBox ""Way cool!""" 
 ClickEventProc = True 
 
Exit_ClickEventProc: 
 Exit Function 
 
Error_ClickEventProc: 
 MsgBox Err & " :" & Err.Description 
 ClickEventProc = False 
 Resume Exit_ClickEventProc 
End Function

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.