Open Table statement - MapBasic - 2023

MapInfo MapBasic Reference

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapBasic
Version
2023
Language
English
Product name
MapBasic
Title
MapInfo MapBasic Reference
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:32:32.686312

Purpose

Opens a MapInfo Pro table for input/output. You can issue this statement from the MapBasic window in MapInfo Pro.

Syntax

Open Table filename [ As tablename ] 
	[ Hide ] [ ReadOnly ] [ Interactive ] [ Password pwd ]
	[ NoIndex ] [ MRU ] [ View Automatic ] [ DenyWrite ] 
	[ VMGrid | VMRaster | VMDefault ]

filename is a string which specifies which MapInfo table to open.

tablename is a string representing an "alias" name by which the table should be identified.

pwd is a string representing the database-level password for the database, to be specified when database security is turned on. Applies to Access tables only.

VMGrid treats all VM GRD files as Grid Layers when opened.

VMRaster treats all VM GRD files as Raster Layers when opened.

VMDefault treats GRD as Raster or Grid depending on existence of RasterStyle 6 1 tag in TAB file.

MRU is an optional token. If present, it will add the name of the successfully opened table into the MRU list.

Description

The Open Table statement opens an existing table. The effect is comparable to the effect of an end-user choosing the Open command and selecting a table to open. A table must be opened before MapInfo Pro can process that table in any way.

Note: The name of the file to be opened (specified by the filespec parameter) must correspond to a table which already exists; to create a new table from scratch, use the Create Table statement. The Open Table statement only applies to MapInfo tables; to use files that are in other formats, use the Register Table statement and the Open File statement.

If the statement includes an As clause, MapInfo Pro opens the table under the "alias" table name indicated by the tablename parameter, rather than by the actual table name. This affects the way the table name appears in lists, such as the list that appears when a user chooses the Close Table command. Furthermore, when an Open Table statement specifies an alias table name, subsequent MapBasic table operations (for example, a Close Table statement) must refer to the alias table name, rather than the permanent table name. An alias table name remains in effect until the table is closed. Opening a table under an alias does not have the effect of permanently renaming the table.

If the statement includes the Hide clause, the table will not appear in any dialog boxes that display lists of open tables (for example, the Close dialog box). Use the Hide clause if you need to open a table that should remain hidden to the user. If the statement includes the ReadOnly clause, the user is not allowed to edit the table.

The optional Interactive keyword tells MapBasic to prompt the user to locate the table if it is not found at the specified path. The Interactive keyword is useful in situations where you do not know the location of the user's files. If the statement includes the NoIndex keyword, the MapInfo index will not be re-built for an MS Access table when opened.

View Automatic is an optional clause to the Open Table statement that allows the MapInfo table, workspace or application file associated with a hotlink object to launch in the currently running instance of MapInfo Pro or start a new instance if none is running. If View Automatic is present, after opening the table, MapInfo Pro will either add it to an existing mapper, open a new mapper, or open a browser. This is especially useful with the HotLinks feature.

DenyWrite is an optional clause for MS Access tables only, If it is specified, other users will not be able to edit the table. If another user already has read-write access to the table, the Open Table command will fail.

Attempting to open two tables that have the same name

MapInfo Pro can open two separate tables that have the same name. In such cases, MapInfo Pro needs to open the second table under a special name, to avoid conflicts. Depending on whether the Open Table statement includes the Interactive keyword, MapBasic either assigns the special table name automatically, or displays a dialog box to let the user select a special table name. \

For example, a user might keep two copies of a table called "Sites", one copy in a directory called 2006 (for example, "C:\2006\SITES.TAB") and another, perhaps newer copy of the table in a different directory (for example, "C:\2005\SITES.TAB"). When the user (or an application) opens the first Sites table, MapInfo Pro opens the table under its default name ("Sites"). If an application issues an Open Table statement to open the second Sites table, MapInfo Pro automatically opens the second table under a modified name (for example, "Sites_2") to distinguish it from the first table. Alternately, if the Open Table statement includes the Interactive clause, MapInfo Pro displays a dialog box to let the user select the alternate name.

Regardless of whether the Open Table statement specifies the Interactive keyword, the result is that a table may be opened under a non-default name. Following an Open Table statement, issue the function call TableInfo(0, TAB_INFO_NAME) to determine the name with which MapInfo Pro opened the table.

Attempting to open a table that is already open

If a table is already open, and an Open Table As statement tries to re-open the same table under a new name, MapBasic generates an error code. A single table may not be open under two different names simultaneously.

However, if a table is already open, and then an Open Table statement tries to re-open that table without specifying a new name, MapBasic does not generate an error code. The table simply remains open under its current name.

Example

The following example opens the table STATES.TAB, then displays the table in a Map window. Because the Open Table statement uses an As clause to open the table under an alias (USA), the Map window's title bar will say "USA Map" rather than "States Map."

Open Table "States" As USA
Map From USA

The next example follows an Open Table statement with a TableInfo() function call. In the unlikely event that a separate table by the same name (States) is already open when you run the program below, MapBasic will open "C:STATES.TAB" under a special alias (for example, "STATES_2"). The TableInfo() function call returns the alias under which the "C:STATES.TAB" table was opened.

Include "MAPBASIC.DEF"
Dim s_tab As String
Open Table "C:states" 
s_tab = TableInfo(0, TAB_INFO_NAME)
Browse * From s_tab
Map From s_tab

See Also:

Close Table statement, Create Table statement, Delete statement, Fetch statement, Insert statement, TableInfo() function, Update statement