I was searching how to check whether a particular table exists in a Access database using ADORDD for a long time.
Now, a very simple (quick and dirty? ) solution came to my mind. I modified ADORDD.1 sample. Please check and send your comments.
Code: Select all
/*
* MINIGUI - Harbour Win32 GUI library Demo
*
* Copyright 2002-2008 Roberto Lopez <harbourminigui@gmail.com>
* http://harbourminigui.googlepages.com/
* Based on ADORDD samples included in Harbour distribution
*/
#include "adordd.ch"
#include "minigui.ch"
function Main()
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 640 HEIGHT 480 ;
TITLE 'MiniGUI Browse Demo)' ;
MAIN NOMAXIMIZE ;
ON INIT CreateTable() ;
ON RELEASE CloseTable()
@ 10,10 BROWSE Browse_1 ;
WIDTH 610 ;
HEIGHT 390 ;
HEADERS { 'First' , 'Last' , 'Age' } ;
WIDTHS { 150 , 150 , 150 } ;
WORKAREA Table1 ;
FIELDS { 'table1->First' , 'table1->Last' , 'table1->Age' }
END WINDOW
CENTER WINDOW Form_1
Form_1.Browse_1.SetFocus
ACTIVATE WINDOW Form_1
return nil
Function ADOTableExists(cDatabase, cTable, cAlias)
// following condition checking was added as reported by Swapan
if !file(cDatabase)
return .f.
endif
if select(cAlias) > 0
return .t.
endif
use &cDatabase via "ADORDD" TABLE cTable alias &cAlias
if select(cAlias) = 0
return .f.
endif
select &cAlias
use
return .t.
Procedure CreateTable
if !ADOTableExists("test2.mdb", "table1", "table1")
DbCreate( "test2.mdb;table1", { { "FIRST", "C", 10, 0 },;
{ "LAST", "C", 10, 0 },;
{ "AGE", "N", 8, 0 } }, "ADORDD" )
endif
USE test2.mdb VIA "ADORDD" TABLE "table1" alias table1
APPEND BLANK
table1->First = "Homer"
table1->Last = "Simpson"
table1->Age = 45
APPEND BLANK
table1->First = "Lara"
table1->Last = "Croft"
table1->Age = 32
GO TOP
Return
Procedure CloseTable
USE
Return
Sudip