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

Avatar of undefined
Last Comment
peter57r

8/22/2022 - Mon
Banthor

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

For file name:  currentproject.name
ASKER CERTIFIED SOLUTION
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
trbaze

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.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
jerryb30

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.
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

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
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

So, Short Answer is actually Yes :-)
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
jerryb30

Silly me, I used currentdb.name. Works in 2007, too.  Point to Joe.
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

And finally:

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

mx
jerryb30

currentdb.name does not work in the Access 2007 I have
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Hamed Nasr

What do want to do?
Give an example.
peter57r

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.
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Grasshopper3

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

Solved problem
peter57r

I thought it was DatabaseMX who provided the solution?