Previous Thread

7/5/2006 1:46:01 PM    How Do I Programmatically Append From DBF?
OK, here's the long story: 
 
I'm writing a Project Management application that I want to integrate with 
 
Primavera.  I want to be able to import Primavera data, save it into a table 
 
in my database, allow users to work with it there, and then export it again 
 
to Primavera.  To do this, the Primavera file must be saved in DBF format, 
 
which is no big problem, because Primavera can do that automatically. 
 
The problem is, I don't want users to have to tell the application which 
 
table to import to, and then have to programmatically allow them to link all 
 
my forms to some new table they may have named arbitrarily.  Instead, I'd 
 
rather import the DBF data using a RunSQL command into a table I've already 
 
created, designed for the purpose, and linked my forms to appropriately. 
 
Therefore, I need a two-click system. 
 
1) Select the DBF file to import from. 
 
2) Import the data from the DBF file to my pre-made table. 
 
I'm fairly certain the first option is easy.  The second option is not (for 
 
me).  Here is my code so far...I'm starting slow, just trying to import the 
 
Task name from the Primavera DBF file. 
 
Dim objConn As ADODB.Connection 
 
Dim objRS As ADODB.Recordset 
 
Dim sPath As String, sFile As String, sSQL As String 
 
Set objConn = New ADODB.Connection 
 
Set objRS = New ADODB.Recordset 
 
sPath = "C:\P3WIN\P3OUT" 
 
sFile = "P3.DBF" 
 
sSQL = "SELECT * FROM P3" 
 
objConn.Open "Driver={Microsoft dBASE Driver (*.dbf)};" & 
 
"DriverID=277;" & "Dbq=" & sPath   '"Dbq=c:\somepath" 
 
objRS.Open sSQL, objConn, , , adCmdText 
 
Do While Not objRS.BOF And Not objRS.EOF 
 
DoCmd.RunSQL "INSERT INTO tblPrimaveraDetail ( 
 
PD_ActivityDescription ) SELECT TITLE FROM objRS;" 
 
Loop 
 
The hard part is the RunSQL command, I believe.  How do I tell it to select 
 
it's data from the recordset I have created?  Is this the best way to do it? 
 
Does anyone have any comments or suggestions? 
 
Thanks! 
 
Dustin



7/6/2006 6:35:30 AM    Re: How Do I Programmatically Append From DBF?
Hi Dustin, 
 
INSERT INTO tblPrimaveraDetail 
 
(PD_ActivityDescription) 
 
SELECT TITLE 
 
FROM objRS; 
 
AFAIK that can't work, because objRS is an ADODB.Recordset and an SQL 
 
FROM clause requires either a table or a query. Also, using RunSQL is 
 
almost never a good idea when you're working in VBA with Connection or 
 
Database objecets: use their Execute methods instead. 
 
So looks as if you need to forget about objRS and do something like 
 
sSQL = "INSERT INTO (PD_ActivityDescription) " _ 
 
& "SELECT TITLE FROM P3;" 
 
objConn.Open blah blah 
 
objConn.Execute sSQL 
 
On Wed, 5 Jul 2006 13:46:01 -0700, Dustin Ventin 
 
<DustinVentin@discussions.microsoft.com> wrote: 
 
-- 
 
John Nurick [Microsoft Access MVP] 
 
Please respond in the newgroup and not by email.