Solved

URGENT: open table from another database

Posted on 2003-11-23
8
657 Views
Last Modified: 2008-01-09

i want to open a table from another database.  the path to the other database is input by the user

i thought this would work:  
   DoCmd.RunSQL "SELECT * FROM " & tableName & " IN '" & dbPath & "'"

but it give me rt error 2342: a runsql action requires an argument consisting of a SQL statement.  strange b/c if i create a new query and copy the sql into it, i can run it no problem
0
Comment
Question by:spathiphylum
8 Comments
 

Author Comment

by:spathiphylum
ID: 9807661
clarification:  i want to open the table in datasheet mode (so the user can see/edit it)
0
 
LVL 2

Expert Comment

by:Team929
ID: 9807735
first off, I see a ; missing from your sql statement. So try:

DoCmd.RunSQL "SELECT * FROM " & tableName & " IN '" & dbPath & "';"
0
 
LVL 2

Expert Comment

by:HobsonT
ID: 9807742
If you look at the help for RunSQL it states:
"You can use the RunSQL action to run a Microsoft Access action query by using the corresponding SQL statement."
This means that only action queries will run this way. (eg Delete, make table)

This is modified from the code at:
http://support.microsoft.com/default.aspx?scid=kb;en-us;210242&Product=acc2000

Public Sub ShowQuery(byval tableName as string, byval dbPath as string)
Dim db As DAO.Database
Dim QD As QueryDef

Set db = CurrentDb()

' Delete the existing dynamic query; trap the error if the query does
' not exist.
On Error Resume Next
db.querydefs.Delete ("Dynamic_Query")
On Error GoTo 0

Set QD = db.CreateQueryDef("Dynamic_Query", "SELECT * FROM " & tableName & " IN '" & dbPath & "';")
DoCmd.OpenQuery "Dynamic_Query"
End Sub

Hope this helps
0
 
LVL 33

Accepted Solution

by:
Mike Eghtebas earned 500 total points
ID: 9807749
DoCmd.RunSQL will run Update, Insert Into, etc except Select.

You need to link it and opent it using a query.  Do you want the code to do this?

Mike
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 7

Expert Comment

by:wsteegmans
ID: 9807767
If you look in Access-Help, you find this with the RunSQL:

You can use the RunSQL action to run a Microsoft Access action query by using the corresponding SQL statement. You can also run a data-definition query.

The part Action Query is important here. With RunSQL you can update, insert or delete records in a table (in the current DB or another DB). However, selecting isn't the case here.

Commands you can use with RunSQL:
Append: INSERT INTO
Delete: DELETE
Make-table: SELECT...INTO
Update: UPDATE

What is the purpose of doing this SELECT-Statement in you code?
0
 

Author Comment

by:spathiphylum
ID: 9807790
so the "IN" portion is something that MS added in access?  it's not SQL?
0
 

Author Comment

by:spathiphylum
ID: 9809052
here's what i ended up with:

Public Sub DisplayTable(tableName As String, dbPath As String)
    'DoCmd.RunSQL "SELECT * FROM " & tableName & " IN '" & dbPath & "'"

    If tableExists(tableName) Then
        DoCmd.DeleteObject acTable, tableName
    End If
    DoCmd.TransferDatabase acLink, "Microsoft Access", dbPath, acTable, tableName, tableName, False
    DoCmd.OpenTable tableName
End Sub
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
ID: 9809062
You may whish to use:

DoCmd.OpenQuery "qQueryName"

If you wish to include specific fields and sorts or apply some criteria to limit the display.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now