Access/VBA Library

INI_Remove

Remove a section or key from the INI-file.

Syntax

INI_Remove( index )
Parameters
Name Type Description
index String Required. Pair of section and key, separated by a dot or only the name of the section to be removed.
Code
Public Sub INI_Remove(ByVal index As String)
    ' Remove section if index is a section
    If INI_SectionExists(index) Then
        Call WritePrivateProfileString(index, vbNullString, vbNullString, INI_Filename())
    ElseIf INI_KeyExists(index) Then
        ' Remove key
        Call WritePrivateProfileString( _
                 GetSectionFromIndex(index), _
                 GetKeyFromIndex(index), _
                 vbNullString, _
                 INI_Filename())
    End If
    
End Sub

Remarks

  • When the INI-file contains a section "database" and the default section also contains a key "database" then INI_Remove( "database" ) will just remove the section "database". The key "config.database" will remain! If you want to remove this key, call INI_Remove( "config.database" ).

See also

  • INI_SectionExists
  • INI_KeyExists
  • WritePrivateProfileString