Solved

URGENT: open table from another database

Posted on 2003-11-23
8
648 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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.

747 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

9 Experts available now in Live!

Get 1:1 Help Now