Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Zul Rahim
  Where is Zul Rahim?
 Houston
 Texas - United States
 Zul Rahim
 To: zakaria hamieh
  Where is zakaria hamieh?
 beirut
 Lebanon
 zakaria hamieh
 Tags
Subject: RE: Access Database
Thread ID: 416495 Message ID: 416565 # Views: 47 # Ratings: 1
Version: Visual FoxPro 9 SP2 Category: Databases, Tables and SQL Server
Date: Wednesday, December 31, 2014 6:43:33 AM         
   


> dear expert
>
> first allow me to say "Merry Christmas & A happy New Year" for all members and visitors of Foxite
> i hope next year will be Successful and helpful year for all of us
>
> i think this question is already asked but may be i did not search in the correct words to find what i need
>
> i have an access database with specific structures that i want to append and modify data from within a visual foxpro form
>
> any help will be appreciated
> thank you in advance
> zakaria
>
> foxes will always be running


LOCAL lcMDB, lnConnHandle, lnTables, lcSQLCommand, lnMDBData, lcDbfName, lcVFPDBCPath
	  
LOCAL ARRAY laErr(1)

*-- Select Dir for VFP Data
lcVFPDBCPath = GETDIR()
IF EMPTY(lcVFPDBCPath)
   RETURN
ENDIF


*-- Get the Access database
lcMDB = GETFILE('MDB')

*-- Continue if we've lcMDB
IF !EMPTY(lcMDB)

   *-- Use a SQLStringConnect to connect to the MDB File
   lnConnHandle = SQLSTRINGCONNECT('DRIVER=MICROSOFT ACCESS DRIVER (*.MDB);DBQ='+lcMDB)
   IF lnConnHandle > 0
      
      *-- Find what tables are contained in the MDB file
      lnTables = SQLTABLES(lnConnHandle, 'TABLE')
		
      IF lnTables > 0
        *-- create a new DBC named 'Mdb2vfpDbc'
        CREATE DATABASE (ADDBS(lcDBCPath) + 'Mdb2vfpDbc')
			
	*-- Select SQLResult and scan thru the cursor
	SELECT SQLResult
	SCAN
	   *-- Build a SQL SELECT statement to pass to SQLEXEC()
	   lcSQLCommand = "Select * from [" + ALLTRIM(SQLResult.table_name) + "]"
		
	   lnMDBData = SQLEXEC(lnConnHandle,lcSQLCommand,'mdbData')
	   IF lnMDBData > 0
		*-- SQLExec() was successful
		lcDbfName = STRTRAN(ALLTRIM(SQLResult.table_name)," ","_")
		lcDbfName = ADDBS(lcVFPDBCPath) + lcDbfName

		*-- copy table structure and data to a DBF file
		SELECT mdbData
		COPY TO (lcDbfName) DATABASE vfpDbc
	   ENDIF  
	ENDSCAN
      ENDIF
		
      *-- Disconnect
      SQLDISCONNECT(lnConnHandle)
   
   ELSE

      *-- SQLStringConnect failed
      MESSAGEBOX('ODBC Connection failed',0+48,'ODBC')
      *-- Call AERROR()
      AERROR(laErr)
      *-- Display the error
      DISPLAY MEMORY LIKE laErr
   ENDIF
ENDIF




Zul Rahim
VIVA LA FOX

ENTIRE THREAD

Access Database Posted by zakaria hamieh @ 12/30/2014 11:07:04 AM
RE: Access Database Posted by Stefan Wuebbe @ 12/30/2014 11:30:09 AM
RE: Access Database Posted by Zul Rahim @ 12/31/2014 6:43:33 AM
RE: Access Database Posted by Zia Mughal @ 12/31/2014 9:35:16 AM