Access/VBA Library


Remove a section or key from the INI-file.


INI_Remove( index )
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.
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, _
    End If
End Sub


  • 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