LJG
asked on
=Dir(CurrentDb.Name) Not working in Report --> Control Source
Version -->: Access 2010
Problem:
Dir(CurrentDb.Name) works in vba but does not work as a control Source in a Textbox on a report.
Facts:
1) It's in the text box as --> =Dir(CurrentDb.Name)
2) It came over from Access 2003 where it was used all the time.
3) The database is an --> accdb
3) I don't know if this has anything to do with it, but I can't put DAO reference (Microsoft DAO 3.6 Oject Library) - It gives me an error -->Name conflicts with existing module, project, or object Library
Thanks in advance for any help.
LJG
Problem:
Dir(CurrentDb.Name) works in vba but does not work as a control Source in a Textbox on a report.
Facts:
1) It's in the text box as --> =Dir(CurrentDb.Name)
2) It came over from Access 2003 where it was used all the time.
3) The database is an --> accdb
3) I don't know if this has anything to do with it, but I can't put DAO reference (Microsoft DAO 3.6 Oject Library) - It gives me an error -->Name conflicts with existing module, project, or object Library
Thanks in advance for any help.
LJG
" It came over from Access 2003 where it was used all the time."
Not surprising, because a lot of things got 'tightened up' starting in A2007, some of which were probably never intended to work, but did.
"It gives me an error -->Name conflicts with existing module, project, or object Library"
Can you post a screen shot of your References ?
mx
Not surprising, because a lot of things got 'tightened up' starting in A2007, some of which were probably never intended to work, but did.
"It gives me an error -->Name conflicts with existing module, project, or object Library"
Can you post a screen shot of your References ?
mx
ASKER
Sl8rz
Thanks for the response.
The article doesn't help - but thanks for trying.
I can make Dir(CurrentDb.Name) work in code so I can make things work, but I'm looking for why it doesn't work as a control source for a field in a report in 2010 but works fine 2003.
Thanks for the response.
The article doesn't help - but thanks for trying.
I can make Dir(CurrentDb.Name) work in code so I can make things work, but I'm looking for why it doesn't work as a control source for a field in a report in 2010 but works fine 2003.
ASKER
DatabaseMX
With you saying things got 'tightened up' are you saying that
= Dir(CurrentDb.Name)
should never of worked as a control source on a field?
Even further are you saying Internal and written functions shouldn't work as a control source in fields?
Are you trying to scare me? :)
Found the answer for - "It gives me an error -->Name conflict..." -
https://www.experts-exchange.com/questions/27819249/Solve-failing-VBA-DAO-code-with-Access-2010-'accdb'-databases.html
With you saying things got 'tightened up' are you saying that
= Dir(CurrentDb.Name)
should never of worked as a control source on a field?
Even further are you saying Internal and written functions shouldn't work as a control source in fields?
Are you trying to scare me? :)
Found the answer for - "It gives me an error -->Name conflict..." -
https://www.experts-exchange.com/questions/27819249/Solve-failing-VBA-DAO-code-with-Access-2010-'accdb'-databases.html
I'm saying that I suspect CurrentDB.whatever was never supposed to work in a Control Source. I've experienced the exact same issue ... using RecordsetClone.Recordcount , etc.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK - for discussion purposes
I consider the below facts (You know - Perceived Reality)
1) CurrentDb.Name will return something like --> C:\Develop\MyDatabase.accd b
2) Dir( "C:\Develop\MyDatabase.acc db") will return --> MyDatabase.accdb <-- because there is only one file in that directory with that name.
3) If the above is true then Dir(CurrentDb.Name) will return --> MyDatabase.accdb <-- (which by the way it does in code)
So why doesn't --> =Dir(CurrentDb.Name) work in a text box but it does in code.
Here is the workaround - but I am one of those guys who wants to know WHY something doesn't work so I can avoid things in the future.
If the text field has a name of txtDBName then the below works.
Me.txtDbName.ControlSource = Chr(61) & Chr(34) & Dir(CurrentDb.Name) & Chr(34)
I consider the below facts (You know - Perceived Reality)
1) CurrentDb.Name will return something like --> C:\Develop\MyDatabase.accd
2) Dir( "C:\Develop\MyDatabase.acc
3) If the above is true then Dir(CurrentDb.Name) will return --> MyDatabase.accdb <-- (which by the way it does in code)
So why doesn't --> =Dir(CurrentDb.Name) work in a text box but it does in code.
Here is the workaround - but I am one of those guys who wants to know WHY something doesn't work so I can avoid things in the future.
If the text field has a name of txtDBName then the below works.
Me.txtDbName.ControlSource
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes, I'm being lazy here by not testing this myself...sorry. However, I think that the DIR command (since it's been tightened up by MS) will return a collection of some sort. And even if that collection is one item, you have to specify which item you want. My thinking follows that if an array (not a true collection I know) has only one item in it, I still have to specify the zeroth item to do anything with that item. I can't just assign the contents of the whole array to a control that display only one item.
"So why doesn't --> =Dir(CurrentDb.Name) work in a text box but it does in code."
I think I explained that in my first post. However, I do not know the exact reason, sorry.
" but I am one of those guys who wants to know WHY something doesn't work so I can avoid things in the future"
Me too ... but still.
Also:
Whereas Chr(61) & Chr(34) & Dir(CurrentDb.Name) & Chr(34) in code works when the ControlSource is set to this, it's (apparently) not equivalent to doing it directly in the Control Source.
I think I explained that in my first post. However, I do not know the exact reason, sorry.
" but I am one of those guys who wants to know WHY something doesn't work so I can avoid things in the future"
Me too ... but still.
Also:
Whereas Chr(61) & Chr(34) & Dir(CurrentDb.Name) & Chr(34) in code works when the ControlSource is set to this, it's (apparently) not equivalent to doing it directly in the Control Source.
"DIR command (since it's been tightened up by MS)"
I seriously the DIR command has changed at all. That would be a disaster.
If you are referring to my use of 'tightening up', I was only referring to using constructs like
=CurrentDB.Name in a ControlSource.
mx
I seriously the DIR command has changed at all. That would be a disaster.
If you are referring to my use of 'tightening up', I was only referring to using constructs like
=CurrentDB.Name in a ControlSource.
mx
ASKER
Thanks All!
http://answers.microsoft.com/en-us/office/forum/office_2007-access/dir-function-in-vba/c0651b08-8d77-4d03-a4aa-a29eeb4d1155