Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Transferring data from Excel to a VFP table
Message
From
20/11/2002 08:54:52
 
 
To
19/11/2002 21:52:28
Henry Ravichander
RC Management Systems Inc.
Saskatchewan, Canada
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00724558
Message ID:
00724703
Views:
18
I'm not entirely sure what you mean by transferring manually and you want to point to a dialog box and transfer the file to excel. The only simple way I know is to open Access, open a database, choose a table, and do a 'Save As' to Excel.

As far as the learning curve for ADO, I don't think it's really so bad. If I can learn it, almost any non-comatose person can.

Here is some very basic stuff to open a connection, open a recordset, and loop through it to get field information. This is very basic, but hopefully should get you on track.
*open connection to access database
* oConnection is the connection object
* and it will be used to open an access recordset
*    cDir is default directory were mdb resides
*    cDatabase is the name of the mdb
*    cId - user id (if there is one) or empty string
*    cPwd - user password (if there is one) or empty string

cConnString = "Driver={Microsoft Access Driver (*.mdb)};DefaultDir=" + cDir + ;
              ";DBQ=" + cDatabase + ;
              ";User Id=" + cID + ;
              ";Password=" + cPwd
oConnection = CreateObject('ADODB.Connection')
oConnection.Open(cConnString)


*open recordset using above connection
*    oConnection is the connection previously opened
*    cTable is name of table in the database
*    oRst is the recordset object
*    cOpenString - select string to bring back a recordset
*    nWhere - where cursor will be opened - either server (adUseServer) or client (adUseClient)
*    nHow - how opened - adLockOptimistic,adLockPessimistic,adLockBatchOptimistic,adLockReadOnly
* the  adXXXX definitions come from adovfp.h include file

If Type('oConnection') = 'O' and !IsNull(oConnection)	&& exists and is not null
   If oConnection.State = adStateOpen	&& it's open
      cOpenString = 'Select * from ' + Alltrim(cTable))
      oRst = CreateObject('ADODB.RecordSet')
      oRst.CursorLocation = nWhere
      oRst.Open(cOpenString, oConnection, adOpenStatic, nHow, adFetchAsync + adCmdText)
   Endif
Endif


* loop through the recordset fields with
Do While !(oRst.EOF)
   For nLoop = 0 to oRst.Fields.Count - 1
      FldVal = oRst.Fields(nLoop).Value

      * Other useful field info
      FldName = oRst.Fields(nLoop).Name
      FldType = oRst.Fields(nLoop).Type
      FldSize = oRst.Fields(nLoop).DefinedSize
      FldPrecision = oRst.Fields(nLoop).Precision
      FldScale = oRst.Fields(nLoop).NumericScale
   EndFor
   oRst.MoveNext()   && next record
EndDo

* note that you can also refer to the field by name
* ie - oRst.Fields("Fieldname").Value
* so you wouldn't have to do a loop through the fields as above



* Don't forget to close them
oRst.Close()
oConnection.Close()
>>I think your idea below would require the least amount of code. On the other hand, using ADO, you could, if you wanted to, grab the data directly from access into vfp.
>>
>Hi Alan: Thank you for your response. So far I have managed to add records to the master table in the way described earlier in this thread.
>
>I have no clue about using ADO with VFP. what would be the learning curve to implement via ADO?
>
>Also, I am currently transferring the data into Excel manually. Is there a way wherein, I could point to a file in a dialog box, open that file and transfer that to Excel? This would make it a lot easier.
>
>Thanks Alan.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform