Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to close all layers in Mapinfo except one and again add one layer. How to do so in Mapinfo using Mapbasic or without?

share|improve this question
up vote 5 down vote accepted

This will close all layers except one using a layer name to check what to keep open:

Dim i as Integer
Dim tables as Integer
Dim tableName as String

tables = NumTables()

For i = 0 To tables
    tableName = TableInfo(i,TAB_INFO_NAME)
    '' Check to see if the table is anything but the one we are looking for.
    If Not tableName = "{Your table name to check here}" Then
        Close Table tableName 
    End If
share|improve this answer
I would like to ask is hiding layer valid way to to change the selection of any query when I am hiding data from master table and only displaying result using query? – kinkajou Jul 3 '11 at 22:56
closing table closes layer but I would like to hide "Display Off" layer and how to get available layers above code would give error if table is present and layer is not added – kinkajou Jul 4 '11 at 12:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.