?
Solved

URGENT: open table from another database

Posted on 2003-11-23
8
Medium Priority
?
699 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Accepted Solution

by:
Mike Eghtebas earned 2000 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
 
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 34

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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

771 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