Link to home
Start Free TrialLog in
Avatar of Grasshopper3
Grasshopper3

asked on

Access Database name in query

Hi,

Is there syntax that I can use in the design view of an access query that will return the database name of the active database?

Thanks
Avatar of Banthor
Banthor
Flag of United States of America image

Since Access may have linked tables to several databases as well as access data without a connection, you may have to redefine your question

in a label you might be able to set the value to a database property to return the name of the Access File.
Avatar of trbaze
trbaze

For file name:  currentproject.name
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Forgot to mention that for the application title you would use:

currentdb.properties.("AppTitle")

You can create a public function, then call it from the query.
Short answer: No.
Long answer: If, as suggested, you create a function to return the db path and name, yes. Which you could call in deign view, if you use (right click) Build, functions, [db name], [module name],[function name]
Short question: Why? (As suggested, too.) The DB knows itself as currentdb.
This actually works in A2003:

SELECT Table1.ID, [CurrentProject].[Name] AS db
FROM Table1;

OR

SELECT Table1.ID, [CurrentProject].[FullName] AS db
FROM Table1;

OR

SELECT Table1.ID, [CurrentProject].[Path] AS db
FROM Table1;



But I may not work in A2007/10

mx
So, Short Answer is actually Yes :-)
Silly me, I used currentdb.name. Works in 2007, too.  Point to Joe.
And finally:

SELECT Table1.ID, [CurrentDB].[Name] AS db
FROM Table1;

mx
currentdb.name does not work in the Access 2007 I have
What do want to do?
Give an example.
Interesting Q given the outcome.  I agree with findings above - All OK in A2003 but currentdb.name doesn't work in A2010  (in a query ).  

As an added bonus (:-) neither of them work  if you save the query and then try to open a recordset based on the saved query.  This applies to both A2003 and A2010.
I suspected CurrentDB.Name would work in A2010 (7) ... because Microsoft did something that changed that, OR ... it was never supposed to work.  CurrentProject.WhatEver does work ... BUT, not sure I would put that in 'production' .. because it may not work in the future.

I would suggest what I posted at http:#a38009911 ... which is always going to work.

(But the short answer is ... still yes ... at the moment)
mx
Avatar of Grasshopper3

ASKER

I've requested that this question be deleted for the following reason:

Solved problem
I thought it was DatabaseMX who provided the solution?