• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 503
  • Last Modified:

FileLen in Access 2007

Hello,

I have a simple program that I use FileLen to detemine if I found a file of a given name.  It all works nicely BUT, if I do not set Sandbox mode to 2 in the registry, it will not work at all.  I need to give this program to a user and I do not want to be editing registries on a regular basis.

I want a way to enable the FileLen function without changing the registry.  I am also open to a different command that can solve my issue.  I only need to know if it found the file or not.  Maybe IfExist if there is such a thing.

Thanks
0
vmccune
Asked:
vmccune
  • 5
  • 4
  • 4
  • +1
1 Solution
 
Rey Obrero (Capricorn1)Commented:
did you place your app in a trusted location?

office button > access options > trust center
 click on trust center settings  button
0
 
Dale FyeCommented:
Have you tried the Dir() function?  The dir function accepts several arguments, the first being a filename.  If you pass it a full name, it will return the file name if the file actually exists in the folder you provided.  If not, it returns an empty string (may be null).

I'm not really sure what you mean by "need to know if it found the file or not"

Are you providing a path/file name and then searching for the file?
0
 
vmccuneAuthor Commented:
Trusted Location: Yes

The search looks for FileA,  if the FileLen(FileA) is > 0, it writes the value to a fileSize field and moves on.

If it does not find a number for FileLen(FileA), it looks for FileLen(FileA_1) then _2,_3 up to 5 to try and find the picture.  The pictures are set up by the art dept and for varous reasons, the initial name is not always there.

I also then can provide them a list of pictures I am missing and run some sales reports with pictures.

The code is fine and works without a problem as long as I set Sandbox mode to 2.  This seems to me like a crazy way to get access to this command.  There muct be a better way.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
I'm pretty sure ... this is not going to happen  - even with a Trusted Location set - unless you set Macro Security (aka Sandbox) to Low.  This can be done by the user via the Access UI - or directly in the Registry of course.

mx
0
 
vmccuneAuthor Commented:
It is set to lowest for macro but still will not work without also changeing in the registry.
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
"without also changeing in the registry."
Changing in VIA the UI does change it in the Registry, since that is where the setting is stored.

What version of Access is this ?

mx
0
 
Dale FyeCommented:
"BUT, if I do not set Sandbox mode to 2 in the registry, it will not work at all"

What does "it will not work at all" mean?  Are you getting an error message?  Is it just not returning a value for a valid filename?
0
 
vmccuneAuthor Commented:
2007,

MX, it does not change that value in the registry.  That is why I am asking.

Not work at all.  Pops up with a dialog box that says FileLen as if looking for a value.  I change it in SB and it works fine.
0
 
Dale FyeCommented:
How about using the FileSystemObject:

Public Function fnFileLength(FileName as string) as long

    Dim fso as object, fsoFile as object
    set fso = createobject("scripting.filesystemobject")
    set fsoFile = fso.getfile(FileName)
    fnFileLength = fsofile.size

    set fsoFile = nothing
    set fso = nothing
End Function
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
"MX, it does not change that value in the registry.  That is why I am asking."

Well, as I recall now ... there are two different Registry settings.  Setting Macro Security via the UI definitely changes one of them.  

The setting that is changed by Macro Security is shown below ... you can confirm this yourself via the UI. (this is A2003)
1
0
 
vmccuneAuthor Commented:
This is the one I needed to change.  I have multiple versions of access so I changed in each.
registry.jpg
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
This might be useful and applies to A2007:

http://office.microsoft.com/en-us/access-help/use-sandbox-mode-in-access-2007-HA010167429.aspx

And this includes the above and is more comprehensive. I'm still trying to find the other key - that is referenced in these KBs - on my A2010 system.

http://office.microsoft.com/en-us/access/HA012301901033.aspx
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
"This is the one I needed to change"
Yes ...
Odd - that key (SandBox) does not show under Engines on my A2010 system here at work - or my A2003 system here at work either.

mx
0
 
Dale FyeCommented:
Why mess with the registry settings?

Did you try the FileSystemObject option?

I didn't put any error handling in that so, my guess is that it will raise an error if the file isn't found.
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

  • 5
  • 4
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now