Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 12th, 2008, 09:18 AM
Authorized User
 
Join Date: Apr 2007
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default Query an External Mdb

Anyone know the syntax for a select query of a table outside of the current db I am operating from.

For instance, let's say I am working out of SunsetForms.Mdb and am writing a query to SunsetMainDB.Mdb file. How would I write that query? And, do I need to establish some sort of permanent connection to the external .mdb file upon an open event or something?

I get stumped after something like this attempt:

SELECT JobName
FROM Master_Jobs;

How would the query know where the "Master_Jobs" table is if it is outside the the database which is running the query?

I presume you would want to do a connection through vba first.
If so, how would I go about that?

Thanks for any help you can give me.
Coby.

 
Old January 14th, 2008, 11:17 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

You can do this either through a DSN or a Jet Provider statement.

First you open a connection to the database using the DSN or provider statement. Then you create a recordset on the table using the connection.

So that would look something like (using ADO and a DSN):

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sSQL As String

sSQL = "SELECT JobName FROM Master Jobs"

Set cn = New ADODB.Connection
cn.Open "DSN=YourDSNName;"
rs.Open sSQL, cn, adOpenDynamic, adLockOptimistic

...

Something like that. I use ADO and SQL back ends mostly.

Did any of that help?


mmcdonal

Look it up at: http://wrox.books24x7.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
import data from mdb to another mdb mat41 Classic ASP Professional 3 March 9th, 2007 07:01 AM
Query string to a external javascript file anujrathi ASP.NET 1.0 and 1.1 Professional 1 November 4th, 2006 01:26 AM
Query to extract data from 2 tables of .mdb file Subuana Beginning VB 6 6 March 16th, 2006 04:37 PM
grocertogo.mdb swatigaur BOOK: Beginning ASP.NET 1.0 1 April 12th, 2005 09:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.