how to Select data from an external database?

  • Thread starter Thread starter Michael
  • Start date Start date
M

Michael

Hi,

I am writing a database application, my working database name is "myDB.mdb".
I am trying to write some sql code in a model to import data from another
database,
How can I make my code below works?

data = "C:\Documents and
Settings\TestAccount\Desktop\Prog\Data\2005-01-20-0005.mdb"
sql = "Select * from Assemblies in [" & data & "]"
DoCmd.RunSQL sql
Thank you very much

Michael
 
Try delimiting the path with apostrophes or quote marks instead of
square brackets. This syntax works in my test database:

SELECT * FROM tblMain IN 'C:\Temp\Tony\base1.mdb';

Hi,

I am writing a database application, my working database name is "myDB.mdb".
I am trying to write some sql code in a model to import data from another
database,
How can I make my code below works?

data = "C:\Documents and
Settings\TestAccount\Desktop\Prog\Data\2005-01-20-0005.mdb"
sql = "Select * from Assemblies in [" & data & "]"
DoCmd.RunSQL sql
Thank you very much

Michael
 
I tried it, but it always show me error msg as below:

Run-time error '2342'
A RunSQL action requires an argument consisting of an SQL statement

My query is so simple
data = "C:\Documents and
Settings\TestAccount\Desktop\Prog\Data\2005-01-20-0005.mdb"
sql = "Select * from Assemblies in '" & data & "'"
DoCmd.RunSQL sql

Is there anything wrong?
btw, my PC running Window-XP SP2, Access 2000 SP3, MDAC2.7SP1.

Thanks a lot!!!





John Nurick said:
Try delimiting the path with apostrophes or quote marks instead of
square brackets. This syntax works in my test database:

SELECT * FROM tblMain IN 'C:\Temp\Tony\base1.mdb';

Hi,

I am writing a database application, my working database name is
"myDB.mdb".
I am trying to write some sql code in a model to import data from another
database,
How can I make my code below works?

data = "C:\Documents and
Settings\TestAccount\Desktop\Prog\Data\2005-01-20-0005.mdb"
sql = "Select * from Assemblies in [" & data & "]"
DoCmd.RunSQL sql
Thank you very much

Michael
 
You can only use RunSQL with an Action query (INSERT INTO, DELETE or
UPDATE).

For a SELECT query, you have to create a recordset to return the results of
the query.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Michael said:
I tried it, but it always show me error msg as below:

Run-time error '2342'
A RunSQL action requires an argument consisting of an SQL statement

My query is so simple
data = "C:\Documents and
Settings\TestAccount\Desktop\Prog\Data\2005-01-20-0005.mdb"
sql = "Select * from Assemblies in '" & data & "'"
DoCmd.RunSQL sql

Is there anything wrong?
btw, my PC running Window-XP SP2, Access 2000 SP3, MDAC2.7SP1.

Thanks a lot!!!





John Nurick said:
Try delimiting the path with apostrophes or quote marks instead of
square brackets. This syntax works in my test database:

SELECT * FROM tblMain IN 'C:\Temp\Tony\base1.mdb';

Hi,

I am writing a database application, my working database name is
"myDB.mdb".
I am trying to write some sql code in a model to import data from another
database,
How can I make my code below works?

data = "C:\Documents and
Settings\TestAccount\Desktop\Prog\Data\2005-01-20-0005.mdb"
sql = "Select * from Assemblies in [" & data & "]"
DoCmd.RunSQL sql
Thank you very much

Michael
 
Back
Top