Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

? Append Visual FoxPro ADO Recordset to Access Table

Status
Not open for further replies.

tbanf

Technical User
Mar 18, 2009
2
US
My initial task is to create a standard process to normalize the fields, datatypes, and values of Visual FoxPro datasets so they can be ulimately merged into one dataset. This process will be used by several people who are not necessarily technically inclined.
My logic:
For each client dataset
For each table named in FoxTableList (a list of the tables to import)
Append all records to its corresponding Access table
Then run queries on the appended tables to find anomalies

There are numerous clients, with varied numbers of datasets.

Client
Dataset1
Table1
Table2

Dataset2
Dataset3
And so on...

Most of the tables are in the DBC container for each dataset, some are free tables

Using the Visual FoxPro ODBC driver, I am able to import a single dataset, using pass-though queries, however, I cannot change the ODBC path to get to the next dataset without changing the path, closing Access, then relinking – sometimes twice.
So I am using an ADODB connection to get to the tables, can modify the connection string to get to the next dataset, and can Debug.Print the data using a standard SQL string strSQL=“SELECT * from tblName”.

This is when the trouble begins. I need to append the data from the recordset into a table.
A simple INSERT INTO should work (no, of course not). Whenever I modify strSQL, or create a QueryDef, the modified strSQL and the QueryDef cannot see the table and generates the error
“…Jet cannot find the input table or query “Areas” (Areas is the first table).


Since the FoxPro tables have a different number and types of fields – and records, I want to put them into an array and read from that. However, I’m so frustrated I can’t even comprehend the concept of how to use the array.

Any and all suggestions are appreciated!


The following code runs (I’ve removed the error handling from this snippet)


Code:
Function FoxHunt4()

Dim Cnxn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim rstCnt As Long
Dim varValues, varRow As Variant
Dim intRowCount, intFieldCount, i, j As Long
Dim strCnxn, strFox, strMyTable As String 
‘strFox and strMyTable will be passed, here only for testing

strFox = "Areas"
strMyTable = “myAreas”

'VFP connect string
strCnxn = "Driver={Microsoft FoxPro VFP Driver (*.dbf)};" _
 & "SourceDB=G:\LES\Data\Some.DBC;SourceType=DBC;"

Set Cnxn = New ADODB.Connection
Cnxn.Open strCnxn
   
Set rst = New ADODB.Recordset
rst.Open strFox, Cnxn, adOpenKeyset, adLockReadOnly, adCmdTable

rstCnt = rst.RecordCount
varValues = rst.GetRows(rstCnt)
intFieldCount = UBound(varValues, 1)
intRowCount = UBound(varValues, 2)

‘This is where the data should be appended to strMyTable

For j = 0 To intRowCount
For i = 0 To intFieldCount
Debug.Print "Row " & j & ", Field " & i & ": " & varValues(i, j)
Next
Next

Debug.Print rstCnt
rst.Close
   
End Function
 
Since no one has replied i will give you my 2 pence/cents worth (depending on location).

Dont know anything FoxPro but if you are opening as a ADO recordset I am assuming normal rules apply

strFox needs to be a valid sql statement - try "Select * from Areas".
To get the data into the access table you can do the same thing open a recordset on the access database then use .addnew then .update (you can use the existing access connection)
Dont need to use .Getrows just loop around the foxpro recordset using .movenext

this link answering someone else will clarify

Hope this is of help
H
 
strFox needs to be a valid sql statement - try "Select * from Areas".
Just to clear something up, as the options used are set to adCmdTable a table name will quite happily suffice for the Source parameter of the Open() method (I can't test with FoxPro tables but it certainly does for access).

Hope this helps

HarleyQuinn
---------------------------------
You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
yes - didnt notice that - i dont normally use that parameter
 
Thank you for your responses! I'll let you know how it goes - thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top