Link to home
Start Free TrialLog in
Avatar of vmccune
vmccuneFlag for United States of America

asked on

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
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

did you place your app in a trusted location?

office button > access options > trust center
 click on trust center settings  button
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?
Avatar of vmccune

ASKER

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.
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
Avatar of vmccune

ASKER

It is set to lowest for macro but still will not work without also changeing in the registry.
"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
"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?
Avatar of vmccune

ASKER

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.
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
"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)
User generated image
Avatar of vmccune

ASKER

This is the one I needed to change.  I have multiple versions of access so I changed in each.
registry.jpg
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
"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
ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
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