DeleteLines Method

Microsoft Access Visual Basic

expression.DeleteLines(StartLine, Count)

expression    Required. An expression that returns one of the objects in the Applies To list.

StartLine   Required Long. A Long value that specifies the number of the line from which to begin deleting.

Count   Required Long. A Long value that specifies the number of lines to delete.

Remarks

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.

Example

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
        Else
            MsgBox "Line contains text in addition to '" _
                & strText & "'."
        End If
    Else
        MsgBox "Text '" & strText & "' not found."
    End If
    DeleteWholeLine = True
    
Exit_DeleteWholeLine:
    Exit Function
    
Error_DeleteWholeLine:
    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."
    Else
        Debug.Print "Constant declaration not deleted."
    End If
End Sub