Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Records From VFP To Append to MS Access Table
Message
From
14/03/2008 08:33:56
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
14/03/2008 02:25:26
Ed Hizon
Skswood Sdn. Bhd
Kuala Belait, Brunei
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01302047
Message ID:
01302084
Views:
25
>Hi everyone,
>
>I have created a program from VFP and would like the records be appended to an MS Access Table. Is there a special code to be used in order to append the records from VFP to MS Access when a button is clicked. ALl of the fields I used for VFP are the same fields used in MS Access.
>
>Thanks.

Ed,
Create a cursor adapter using ACE OLEDB driver. Rest is not much different than handling a buffered VFP table. ie:(mostly written using Data Explorer):
Local loAccess As CursorAdapter,;
  oConn As ADODB.Connection,;
  oRS As ADODB.Recordset, ;
  oException As Exception, ;
  cConnString As String

* Handle connections - insert connection code
cConnString = [Provider=Microsoft.ACE.OLEDB.12.0;]+;
  [Data Source=C:\Program Files\Microsoft Office\OFFICE11\SAMPLES\NorthWind.mdb;Persist Security Info=False]

Try
  oConn  = Createobject('ADODB.Connection')

  * Ensure that you handle userid and password if not
  * specified in connection string.
  *   ex. oConn.Open(cConnString, userid, password)
  oConn.Open(cConnString)

  oRS = Createobject("ADODB.Recordset")
  oRS.Datasource.CursorLocation = 3   &&adUseClient
  oRS.Datasource.LockType = 3   &&adLockOptimistic
  oRS.ActiveConnection = oConn

  oCA=Createobject("CursorAdapter")
  oCA.DataSourceType = "ADO"
  oCA.Datasource = oRS
  oCA.MapBinary = .T.
  oCA.MapVarchar = .T.

  oCA.Alias = "Customers"
  oCA.SelectCmd = "SELECT * FROM customers"

  If !oCA.CursorFill()
    * Replace with error code here
    Local laError
    Dimension laError[1]
    Aerror(laError)
    Messagebox(laError[2])
  Else
    * Replace with user code here. Code below allows for
    * you to edit and send updates to the backend.
    Local laFlds,lcStr,lnFldCount,i
    Dimension laFlds[1]
    lnFldCount=Afields(laFlds)
    lcStr=""
    For i = 1 To lnFldCount
      lcStr = lcStr + laFlds[m.i,1] +  ","
    Endfor
    oCA.UpdatableFieldList = lcStr
    Insert Into customers (customerID,CompanyName) Values ('VFP#1','Customer added from VFP-1')
    Insert Into customers (customerID,CompanyName) Values ('VFP#2','Customer added from VFP-2')
    Tableupdate(2,.T.,'customers')
    Browse Normal
  Endif

Catch To oException
  * Replace with exception handling code here
  Messagebox(oException.Message)
Endtry
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform