Solved

URGENT: open table from another database

Posted on 2003-11-23
8
668 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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 …

777 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