Creating MDB files programatically

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
karweru
Posts: 220
Joined: Fri Aug 01, 2008 1:51 pm
DBs Used: DBF,mysql,mariadb,postgresql,sqlite,odbc
Contact:

Creating MDB files programatically

Post by karweru »

Hi everyone,

Anyone with an example of how to create an MDB file programatically? Kindly assist.
Kind regards,
Gilbert.
User avatar
gfilatov
Posts: 1116
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: Creating MDB files programatically

Post by gfilatov »

karweru wrote:Hi everyone,

Anyone with an example of how to create an MDB file programatically? Kindly assist.
Hello Gilbert,

Please take a look for the following simple sample (it will required the ADORDD library for proper work):

Code: Select all

/*
 * MINIGUI - Harbour Win32 GUI library Demo
 *
 * Based on ADORDD sample 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 AdoRDD Demo' ;
		MAIN NOMAXIMIZE ;
		ON INIT OpenTable() ;
		ON RELEASE CloseTable()

		@ 10,10 BROWSE Browse_1	;
			WIDTH 610	;
			HEIGHT 390	;	
			HEADERS { 'First' , 'Last' , 'Age' } ;
			WIDTHS { 150 , 150 , 150 } ;
			WORKAREA Test2 ;
			FIELDS { 'Test2->First' , 'Test2->Last' , 'Test2->Age' } 

	END WINDOW

	CENTER WINDOW Form_1

	Form_1.Browse_1.SetFocus

	ACTIVATE WINDOW Form_1

Return nil

Procedure OpenTable

   IF !IsWinNT() .AND. !CheckODBC()
	MsgStop( 'This Program Runs In Win2000/XP Only!', 'Stop' )
	ReleaseAllWindows()
   ENDIF

   IF !FILE('test2.mdb')
	CreateTable()
   ENDIF

   USE test2.mdb VIA "ADORDD" TABLE "table1"

   IF EMPTY( test2->( LastRec() ) )

	APPEND BLANK
	test2->First   := "Homer"
	test2->Last    := "Simpson"
	test2->Age     := 45

	APPEND BLANK
	test2->First   := "Lara"
	test2->Last    := "Kroft"
	test2->Age     := 32

   ENDIF

   GO TOP

Return

Procedure CloseTable

   USE

Return

Procedure CreateTable

   DbCreate( "test2.mdb;table1", { { "FIRST",   "C", 10, 0 },;
                                   { "LAST",    "C", 10, 0 },;
                                   { "AGE",     "N",  8, 0 } }, "ADORDD" )

Return

Static Function CheckODBC()
LOCAL oReg, cKey := ""

	OPEN REGISTRY oReg KEY HKEY_LOCAL_MACHINE ;
		SECTION "Software\Microsoft\DataAccess"

	GET VALUE cKey NAME "Version" OF oReg

	CLOSE REGISTRY oReg

Return !EMPTY(cKey)
Hope that helps :idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
Post Reply