Solved

FileLen in Access 2007

Posted on 2013-01-31
14
489 Views
Last Modified: 2013-03-22
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
Comment
Question by:vmccune
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 4
  • +1
14 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38840630
did you place your app in a trusted location?

office button > access options > trust center
 click on trust center settings  button
0
 
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 38840633
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
 

Author Comment

by:vmccune
ID: 38840694
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75
ID: 38840905
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
 

Author Comment

by:vmccune
ID: 38840984
It is set to lowest for macro but still will not work without also changeing in the registry.
0
 
LVL 75
ID: 38841035
"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
 
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 38841081
"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
 

Author Comment

by:vmccune
ID: 38841141
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
 
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 38841163
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
 
LVL 75
ID: 38841247
"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
 

Author Comment

by:vmccune
ID: 38841324
This is the one I needed to change.  I have multiple versions of access so I changed in each.
registry.jpg
0
 
LVL 75
ID: 38841342
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
 
LVL 75
ID: 38841357
"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
 
LVL 48

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 38841384
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question