Solved

URGENT: open table from another database

Posted on 2003-11-23
8
685 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 34

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
 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

730 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