Using ADO with VFP6, does anyone know how to append data from myTable1 in an Access2K .mdb to myTable2 in the same .mdb? The data currently residing in myTable2 has to remain intact.
Your initial request was to execute the query using ADO within VFP. Your example illustrates you are attempting to automate Access. It's possible to do it both ways.
Automating Access:
lcSQL="INSERT INTO Table2 SELECT * FROM Table1"
mydatabase="C:\mypath\mydatabase.mdb"
oAcc=createobject("access.application"
oAcc.opencurrentdatabase(myDatabase)
oAcc.DoCmd.RunSQL(lcSQL)
oAcc.closecurrentdatabase()
oAcc.quit
release oAcc
Using ADO:
lcConnect="Provider=Microsoft.Jet.OLEDB.4.0;Password=mypass;User ID=myuser;Data Source=C:\mypath\mydatabase.mdb;Persist Security Info=True"
lnAffected=0
lcSQL="INSERT INTO Table2 SELECT * FROM Table1"
oConnection = CreateObject('ADODB.Connection')
oConnection.Open(lcConnect)
IF oConnection.State = 1 && connected sucessfully
oConnection.Execute(lcSQL,@lnAffected)
IF lnAffected > 0
WAIT WIND "Data Transfer: "+TRAN(lnAffected)+"Records"
ENDIF
ELSE
WAIT WIND "Unable to connect"
ENDIF
Of the two approaches, I'd recommend the latter because it creates less overhead on memory and doesnt require Access on the target machine, only MDAC. Jon Hawkins
I have opted to use ADO as per your suggestion. I get an "Incomplete query clause" when I execute this SQL statement:
lcSQL="INSERT INTO Table2 SELECT * FROM Table1"
Since I am updating a couple of tables with this, my code looks like this:
lcSQL="INSERT INTO '" + TableB + "' SELECT * FROM '" + TableA + "'"
TableB's name contains hyphens ("4-2001-info"and TableA's name contains spaces ("info sheet". I think this is the problem, but I can't change the tables' names. Any ideas?
One more question. Is there any simple way of creating one Access table from another Access table as long as the first table has the identical structure of the second? I would like to avoid the whole "CREATE TABLE myTable (myFieldA Integer(6), myFieldB Char(10)...)" thing, since there are nearly 50 fields in one table, and the stucture is just sitting there begging to be used.
I should give you two more stars for that one! I was exploring several ways of developing this and I decided to go with someones suggestion from the Universal Thread. Only now do I see the error of my ways. I bow to your superiority! Anyway, thanks again.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.