Bernard
Bernard

Reputation: 63

Importing MS Access data into VFP

I need to import data from an Access app into VFP tables. I have found solutions on the net for reading VFP data into Access but not the opposite. The connection string suggested by MS* seems to be missing something because I keep getting a dialog box asking me for the type of the source data

I would be grateful for any suggestion and/or explanation.

/bernard

Upvotes: 0

Views: 2872

Answers (1)

DRapp
DRapp

Reputation: 48139

if you are writing the program within VFP, then you can do a connect from VFP to the Access Database without the use of a "DSN", but requires a full connection string setting. Once that is done, you can query the data down into a local VFP cursor, then do what you want once it is in VFP... copy to a VFP table, query subsets of data, add records to another VFP table by whatever criteria you need to process.

nAccessHandle = sqlstringconnect( "DRIVER=Microsoft Access Driver (*.mdb, *.accdb); DBQ=C:\YourFullPath\YourAccessDatabase.accdb;" )

if nAccessHandle < 1
   messagebox( "Invalid connection to access database" )
   return
endif 

*/ Valid handle, now, query down the data to a local VFP cursor
nSQLAns = SQLExec( nAccessHandle, "select * from YourAccessTable", "C_CursorInVFP" )

if nSQLAns < 1
   messagebox( "Unable to get any data..." )
   sqldisconnect( nAccessHandle )
   return
endif

*/ Done with connection
sqldisconnect( nAccessHandle )

select C_CursorInVFP
copy to C:\SomeOtherPath\NowItsAVFPTable

*/ Or, query from it within VFP or loop from it...
select C_CursorInVFP
scan
   */ Look for records in VFP to do/ignore as needed...
   select * from SomeVFPTable ;
      where SomeKey = C_CursorInVFP.KeyFromAccessTable;
      into cursor C_WasItFound readwrite

   if reccount( "C_WasItFound" ) > 0
      */ Do what if it WAS found
   else
      */ Do what if it WAS NOT found
   endif 
endscan 

Upvotes: 1

Related Questions