Solved

MS Access 2007 Remote Query - Can we pass in the folder path?

Posted on 2009-05-07
7
334 Views
Last Modified: 2013-11-29
Hi,

I have several remote queries based on another Access database on another folder.
Is there a way to pass the path  to a remote Query instead of hard code the path?

Thanks,
Luchuan
0
Comment
Question by:luchuanc
  • 4
  • 3
7 Comments
 
LVL 16

Assisted Solution

by:Chuck Wood
Chuck Wood earned 500 total points
ID: 24331126
Do you mean you are querying a linked table (in another database) using a query in your database?
0
 

Author Comment

by:luchuanc
ID: 24331161
Hi cwood-wm-com:

Yes, I have the following sql

select ..... from tblPtVisit in "I:\test\testdb.accdb"

and I:\test\testdb.accdb is another MS Access Database.

Thanks,

Luchuan
0
 
LVL 16

Assisted Solution

by:Chuck Wood
Chuck Wood earned 500 total points
ID: 24331191
I think this is what you need:
Private Function CreateSQL(ByRef strSQL As String, ByVal strDbPath As String)
  strSQL = "SELECT * FROM tblPtVisit IN " & strDbPath
End Function

Open in new window

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.

 

Author Comment

by:luchuanc
ID: 24336902
Hi cwood-wm-com:

Good idea, is there a way to have the query call this function?
(It seems the Query tool does not recognize the VBA function, is this true)

Thanks,

Luchuan
0
 
LVL 16

Accepted Solution

by:
Chuck Wood earned 500 total points
ID: 24337018
Luchuan,
Put the snippet function in a code module (other than a form module) and then put this in a field in your query:

Database: DbPath()
Public Function DbPath()
  DbPath = "I:\test\testdb.accdb"
  ' OR
  'DbPath = Forms!frmMyForm.txtDebPath
End Function

Open in new window

0
 

Author Closing Comment

by:luchuanc
ID: 31579232
Thanks a lot cwood-wm-com.
I finally got time to try your idea, super!


Luchuan
0
 
LVL 16

Expert Comment

by:Chuck Wood
ID: 24472305
You are welcome. I am glad it worked for you. Good luck on your project.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

828 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