473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Reading table from another mdb

I'm building this in Access. I have some queries that pull information from tables, that are currently local. But, when this works, will be in two different access databases. This is one of the working queries.

Expand|Select|Wrap|Line Numbers
  1. SELECT C.SyteDesc, Sum(-1) AS Total
  2. FROM [SELECT T.SyteDesc
  3.      FROM 
  4.         (SELECT DISTINCT SyteDesc
  5.          FROM SpecLognew GROUP BY SyteDesc) AS T 
  6.     GROUP BY T.SyteDesc]. AS T2 INNER JOIN SpecLog AS C ON T2.SyteDesc = C.SyteDesc
  7. GROUP BY C.SyteDesc;
  8.  
I have a text box set in a form with the path of the other mdb's, but still not working out.
I tried replacing the table names with the path of the db and the table name...

At the moment, I'm here...
Expand|Select|Wrap|Line Numbers
  1. SELECT C.SyteDesc, Sum(1) AS Total
  2. FROM [SELECT T.SyteDesc
  3.      FROM 
  4.         (SELECT DISTINCT SyteDesc
  5.          FROM SpecLog
  6. in ' txtOLDMdbPath ' GROUP BY SyteDesc) AS T 
  7.     GROUP BY T.SyteDesc]. AS T2 INNER JOIN Speclog in  txtNewMDBPath ' AS C ON T2.SyteDesc = C.SyteDesc
  8. GROUP BY C.SyteDesc;
  9.  
Was trying to insert the path into the query, so it would remotely query the other db's. Not sure if this is possible.
If anyone has any other suggestions, I'm all ears. I'm going to continue looking into this one though..

Thanks.
Oct 5 '07 #1
6 4567
I simplified it for myself.
Just trying to connect to another mdb file and do a simple select string.

If I go
Expand|Select|Wrap|Line Numbers
  1. SELECT SyteDesc
  2. FROM SpecLog
  3. IN 'C:\Test\Testfile.mdb';
  4.  
It works. But how would I make this possible to link it to a variable that contains the file name?
Oct 5 '07 #2
nico5038
3,080 Expert 2GB
Personally I would go for using a linked table, as that's also supported by the Tools/Database utilities/Linkedtable manager and allows the user to relink when the backend database is moved, without going into code.

To make it "semi" flexible you could define a Public variable in a module (e.g. named modGlobalValues) and place a variable there with the default location of the database to be used.

Nic;o)
Oct 6 '07 #3
That would be nice (I agree with you about the linked table), however the table we are linking to, the database name changes all the time.

Different databases.

What I can't figure out, is how to get the variable into the query.

I do

SELECT SpecLog.SyteDesc
FROM SpecLog IN 'c:\mdb1.mdb'

But if I replace it with a variable, it fails weirdly. Finds the right path to the file, but puts in the name of the variable instead of the file name. If that makes any sense.
Oct 9 '07 #4
nico5038
3,080 Expert 2GB
Ran into the same wierd behaviour.
To manage the changing location you can use a dummy query and fill that with the needed location like:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3. ' Globally available constant with the location of the database:
  4. Public Const pbDatabase As String = "D:\Documents and Settings\Nico\My Documents\Access\Access_2007\Northwind 2007.accdb"
  5.  
  6. Function fncDB() As String
  7. ' The next Dim needs the "Microsoft DAO 3.## Object Library" to be
  8. ' selected in the Tools/References
  9. Dim qd As DAO.QueryDef
  10.  
  11. ' A dummy query named qryDummy only needs to be present, the code
  12. ' will set the contents
  13. Set qd = CurrentDb.QueryDefs("qryDummy")
  14. qd.SQL = "SELECT * FROM Invoices IN '" & pbDatabase & "';"
  15.  
  16. ' ready, qryDummy can be used
  17.  
  18. End Function
  19.  
The code can be expanded to work for multiple databases, e.g. by filling the location from a table.

Nic;o)
Oct 9 '07 #5
Thanks, will try this out.
However, it's not quite what I am after, was just trying to keep it within ms access Query wizard, or whatever you wish to call it.

I'll see if I can get it fixed on my end, and I'll post back here, if not, I'll rewrite it so I can do it this way..

thank you :)
Oct 11 '07 #6
In my particular instance, I found a solution.
Still used ms access query wizards. But for my database changing all the time, I just made a sub that updated the query.

Expand|Select|Wrap|Line Numbers
  1.     sSql = "Select SyteDesc From SpecLog In '" & Me.txtOldMdbPath & "' Where SyteDesc <> Null"
  2.     sSql1 = "Select SyteDesc From SpecLog In '" & Me.txtNewMDBPath & "' Where SyteDesc <> Null"
  3.  
  4. CurrentDb.QueryDefs("qryOldSpecLog").SQL = sSql
  5. CurrentDb.QueryDefs("qryNewSpecLog").SQL = sSql1
  6.  
Which changed the query to point to whatever database I needed it to point to at the time.
So my query would be permanently changed based on what the sub changed it to. Which is fine by me.
This is the result of the query change.

Expand|Select|Wrap|Line Numbers
  1. SELECT SyteDesc
  2. FROM SpecLog IN 'C:\1\Old.MDB'
  3. WHERE SyteDesc <> Null;
  4.  
May not be the best use of things, but it takes a really long boring task and simplifies it down to a matter of a few clicks.

Thanks.
Oct 16 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Dariusz | last post by:
I have PHP code (below) which reads data from a MySQL format database. The problem I am having is trying to find out when the last ID entry was made. When the script is executed, the $gbID is...
2
by: opt_inf_env | last post by:
Hello, I would like to solve the following problem. On the server side I have a file with a sequence of natural numbers (1, 2, 3, 4, 5, ...., n). Each user, after some action, adds new number...
12
by: Anna | last post by:
Hi all, I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try.... in case you should see it later I apologize for posting the same...
3
by: Carl Lindmark | last post by:
*Cross-posting from microsoft.public.dotnet.languages.csharp, since I believe the question is better suited in this XML group* Hello all, I'm having some problems understanding all the ins and...
6
by: ALI-R | last post by:
Hi All; I'm reading the following xml file into a Dataset but there are only 4 datatables in my dataset (which should be 5) Is that because I have two nodes with the same name (detail) in my xml...
1
by: Mr. B | last post by:
VB.net 2003 c/w Framework 1.1 and MS Access db We have a commercial program that does our Acounting and Time Sheets (Timberline). At least once a day our Accounting department runs a Script...
6
by: Klint Gore | last post by:
In the docs it says "Plan-reading is an art that deserves an extensive tutorial, which this is not". Is there one? I've gone beyond simple queries (which are performing well) to the more...
4
by: Amit Maheshwari | last post by:
I need to read text file having data either comma seperated or tab seperated or any custom seperator and convert into a DataSet in C# . I tried Microsoft Text Driver and Microsoft.Jet.OLEDB.4.0...
1
by: Doll | last post by:
I need some help please. I need to show data as disabled but visible on 1 of my forms that is linked up to another table. For example: I have 2 forms and 2 tables. Form A is linked to table...
9
by: dba123 | last post by:
I need some help and direction on what classes and an example or two (article) on how to read an Excel Worksheet and insert one column into a database table column. I am using .NET 2.0 only. What...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.