Module.DeleteLines Method (Access)

The DeleteLines method deletes lines from a standard module or a class module.


expression. DeleteLines( _StartLine_, _Count_ )

expression A variable that represents a Module object.


Name Required/Optional Data Type Description
StartLine Required Long The number of the line from which to begin deleting.
Count Required Long The number of lines to delete.

Return Value



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

To replace one line with another line, use the ReplaceLine method.


The following example deletes a specified line from a module.

Function DeleteWholeLine(strModuleName, strText As String) _ 
 As Boolean 
 Dim mdl As Module, lngNumLines As Long 
 Dim lngSLine As Long, lngSCol As Long 
 Dim lngELine As Long, lngECol As Long 
 Dim strTemp As String 
 On Error GoTo Error_DeleteWholeLine 
 DoCmd.OpenModule strModuleName 
 Set mdl = Modules(strModuleName) 
 If mdl.Find(strText, lngSLine, lngSCol, lngELine, lngECol) Then 
 lngNumLines = Abs(lngELine - lngSLine) + 1 
 strTemp = LTrim$(mdl.Lines(lngSLine, lngNumLines)) 
 strTemp = RTrim$(strTemp) 
 If strTemp = strText Then 
 mdl.DeleteLines lngSLine, lngNumLines 
 MsgBox "Line contains text in addition to '" _ 
 &; strText &; "'." 
 End If 
 MsgBox "Text '" &; strText &; "' not found." 
 End If 
 DeleteWholeLine = True 
 Exit Function 
 MsgBox Err &; " :" &; Err.Description 
 DeleteWholeLine = False 
 Resume Exit_DeleteWholeLine 
End Function

You could call this function from a procedure such as the following, which searches the module Module1 for a constant declaration and deletes it.

Sub DeletePiConst() 
 If DeleteWholeLine("Module1", "Const conPi = 3.14") Then 
 Debug.Print "Constant declaration deleted successfully." 
 Debug.Print "Constant declaration not deleted." 
 End If 
End Sub

See also

Module Object