A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

VBA - CurrentDB() path ??



 
 
Thread Tools Display Modes
  #1  
Old September 12th, 2008, 07:39 PM posted to microsoft.public.access
MVP - WannaB[_2_]
external usenet poster
 
Posts: 12
Default VBA - CurrentDB() path ??

Is there a command that can be used to retrieve the path of the current DB?
I found that Application.CurrentProject.Path can be used with msgbox to
display the current path, but I am looking to be able to set the value of a
const in a modules declarations so that it can be used throughout the
module?
Thank you, I appreciate your help.

  #2  
Old September 12th, 2008, 08:01 PM posted to microsoft.public.access
Chris O'C via AccessMonster.com
external usenet poster
 
Posts: 1,160
Default VBA - CurrentDB() path ??

If you declare a constant, it has to be hard coded so it's resolved at
compile time. Application.CurrentProject.Path is resolved at runtime, so
that doesn't meet the requirement. Any other command is going to have the
same problem.

You could declare a module level variable and set that variable when the db
opens or at another appropriate time.

Chris
Microsoft MVP


MVP - WannaB wrote:
Is there a command that can be used to retrieve the path of the current DB?
I found that Application.CurrentProject.Path can be used with msgbox to
display the current path, but I am looking to be able to set the value of a
const in a modules declarations so that it can be used throughout the
module?


--
Message posted via http://www.accessmonster.com

  #3  
Old September 12th, 2008, 08:06 PM posted to microsoft.public.access
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default VBA - CurrentDB() path ??

Not sure I understand your question. You can't "set the value of a const in
a modules declaration" using a command or function. Constants have to be
declared as constants...

Application.CurrentProject.Path can be used anywhere you want the path:
there's no magic that makes it only work with MsgBox.

Is this contrary to what you're finding?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"MVP - WannaB" nospam at here dot priv wrote in message
...
Is there a command that can be used to retrieve the path of the current
DB?
I found that Application.CurrentProject.Path can be used with msgbox to
display the current path, but I am looking to be able to set the value of
a const in a modules declarations so that it can be used throughout the
module?
Thank you, I appreciate your help.



  #4  
Old September 12th, 2008, 08:29 PM posted to microsoft.public.access
JvC
external usenet poster
 
Posts: 14
Default VBA - CurrentDB() path ??

Use CurrentDB.Name, and strip off the file name.

Left(CurrentDB.Name, InstrRev(currentdb.name))

John

MVP - WannaB explained on 9/12/2008 :
Is there a command that can be used to retrieve the path of the current DB?
I found that Application.CurrentProject.Path can be used with msgbox to
display the current path, but I am looking to be able to set the value of a
const in a modules declarations so that it can be used throughout the module?
Thank you, I appreciate your help.



  #5  
Old September 12th, 2008, 08:41 PM posted to microsoft.public.access
Chris O'C via AccessMonster.com
external usenet poster
 
Posts: 1,160
Default VBA - CurrentDB() path ??

That won't work without the correction I added, and it won't work for a
constant declaration, which is what he/she wants. That value would be
resolved at runtime but for constants the value has to be resolved when it's
compiled.

Chris
Microsoft MVP


JvC wrote:
Use CurrentDB.Name, and strip off the file name.

Left(CurrentDB.Name, InstrRev(currentdb.name, "\"))


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200809/1

  #6  
Old September 12th, 2008, 11:46 PM posted to microsoft.public.access
MVP - WannaB[_2_]
external usenet poster
 
Posts: 12
Default VBA - CurrentDB() path ??


Thank you all, very much
I was able to get my module to work by setting only the db names as
constants in the declarations section. I then used
Application.CurrentProject.Path in each module and concatenated the 2
together. I am not sure why I was previously unable to get
Application.CurrentProject.Path to work on anything but msgbox, (I may have
been using SET, and I am still not clear on when that should be used).
Thanks again.

"Chris O'C via AccessMonster.com" u29189@uwe wrote in message
news:8a189d0a27e85@uwe...
That won't work without the correction I added, and it won't work for a
constant declaration, which is what he/she wants. That value would be
resolved at runtime but for constants the value has to be resolved when
it's
compiled.

Chris
Microsoft MVP


JvC wrote:
Use CurrentDB.Name, and strip off the file name.

Left(CurrentDB.Name, InstrRev(currentdb.name, "\"))


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200809/1

  #7  
Old September 13th, 2008, 06:07 AM posted to microsoft.public.access
Chris O'C via AccessMonster.com
external usenet poster
 
Posts: 1,160
Default VBA - CurrentDB() path ??

Use set only when assigning an object to a variable. If it's a normal data
type either use let or use implied let (it's not written). Examples

set db = currentdb
set accapp = GetObject(, "Access.Application")
let cost = 37.99
let orderno = 4176
orderdate = #9/12/2008#
strlastname = "Wilson"

Chris
Microsoft MVP


MVP - WannaB wrote:

I may have
been using SET, and I am still not clear on when that should be used


--
Message posted via http://www.accessmonster.com

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:50 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.