G
Guest
I need allow users to import DBF databases into my Access application.
However, because this application is going on the market, I cannot allow them
to directly alter anything, and I therefore need a way to link my forms to an
imported table that (theoretically), could be named anything.
To overcome this, I am trying to get Access to import the data, copy it over
to a table that I KNOW will be named correctly (so I can link forms to it),
and then delete the original imported table. I figure its OK to hardcode an
imported table in this way, because it should be named P3 (because it's
actually an exported file from Primavera, and automatically named), and if I
import it, take the data, and delete it all at once, other users shouldn't
have a chance of importing thier own P3.DBF, and Access won't start
concatonating numbers.
So far, I have two attempts:
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\P3.DBF"
sSQL = "INSERT INTO tblPrimaveraDetail (PD_ActivityDescription) SELECT TITLE
FROM P3;"
objConn.Open "Driver={Microsoft dBASE Driver (*.dbf)};" & "DriverID=277;" &
"Dbq=" & sPath
objConn.Execute sSQL
This one doesn't work because it says the driver is incorrect or cannot be
found when I try the objConn.Open line, and I can't find anywhere where
Microsoft explains where to find its drivers. Additionally, I suspect this
won't work because I'm trying to run a SQL string that involves two seperate
data sources.
My other idea is this:
DoCmd.RunCommand acCmdImport
DoCmd.RunSQL "INSERT INTO tblPrimaveraDetail ( PD_ActivityID,
PD_ActivityDescription, PD_BudgetCost, PD_BudgetQuantity, PD_Resource )
SELECT P3.ACT, P3.TITLE, P3.BC, P3.BQ, P3.RES FROM P3;"
DoCmd.RunCommand acCmdDeleteTable
This one works really well, except that the acCmdDeleteTable command errors
out and says it can't be run at this time. (I'm trying to delete the P3 table
so that anyone else who tries to import can still use the P3 table name.
Hopefully, two users don't press the button at the same time.)
So, any thoughts or suggestions? Is there a way to fix one of these
solutions, or perhaps ever a better solution, period?
I greatly appreciate your assistance.
Dustin
However, because this application is going on the market, I cannot allow them
to directly alter anything, and I therefore need a way to link my forms to an
imported table that (theoretically), could be named anything.
To overcome this, I am trying to get Access to import the data, copy it over
to a table that I KNOW will be named correctly (so I can link forms to it),
and then delete the original imported table. I figure its OK to hardcode an
imported table in this way, because it should be named P3 (because it's
actually an exported file from Primavera, and automatically named), and if I
import it, take the data, and delete it all at once, other users shouldn't
have a chance of importing thier own P3.DBF, and Access won't start
concatonating numbers.
So far, I have two attempts:
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\P3.DBF"
sSQL = "INSERT INTO tblPrimaveraDetail (PD_ActivityDescription) SELECT TITLE
FROM P3;"
objConn.Open "Driver={Microsoft dBASE Driver (*.dbf)};" & "DriverID=277;" &
"Dbq=" & sPath
objConn.Execute sSQL
This one doesn't work because it says the driver is incorrect or cannot be
found when I try the objConn.Open line, and I can't find anywhere where
Microsoft explains where to find its drivers. Additionally, I suspect this
won't work because I'm trying to run a SQL string that involves two seperate
data sources.
My other idea is this:
DoCmd.RunCommand acCmdImport
DoCmd.RunSQL "INSERT INTO tblPrimaveraDetail ( PD_ActivityID,
PD_ActivityDescription, PD_BudgetCost, PD_BudgetQuantity, PD_Resource )
SELECT P3.ACT, P3.TITLE, P3.BC, P3.BQ, P3.RES FROM P3;"
DoCmd.RunCommand acCmdDeleteTable
This one works really well, except that the acCmdDeleteTable command errors
out and says it can't be run at this time. (I'm trying to delete the P3 table
so that anyone else who tries to import can still use the P3 table name.
Hopefully, two users don't press the button at the same time.)
So, any thoughts or suggestions? Is there a way to fix one of these
solutions, or perhaps ever a better solution, period?
I greatly appreciate your assistance.
Dustin